Java examples for java.lang:Math Vector
Constructs all embedding vectors of size k for the data.
/*/* w ww . j a v a 2 s . c om*/ * Java Information Dynamics Toolkit (JIDT) * Copyright (C) 2012, Joseph T. Lizier * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ //package com.java2s; public class Main { /** * Constructs all embedding vectors of size k for the data. * There will be (data.length - k + 1) of these vectors returned. * * @param data time series data * @param k embedding length * @return An array of k-length embedding vectors */ public static double[][] makeDelayEmbeddingVector(double[] data, int k) { try { return makeDelayEmbeddingVector(data, k, k - 1, data.length - k + 1); } catch (Exception e) { // The above call should not throw an Exception, handle here // in a RuntimeException so this method doesn't throw one throw new RuntimeException(e); } } /** * Constructs numEmbeddingVectors embedding vectors of size k for the data, * with the first embedding vector having it's last time point at t=startKthPoint * * @param data time series data * @param k embedding length * @param startKthPoint last time point of the first embedding vector * (i.e. use k-1 if you want to go from the start) * @param numEmbeddingVectors the number of embedding vectors to return * (i.e. use data.length-k+1 if you go from the start and want all * of them extracted) * @return a 2D array of k-length embedding vectors. */ public static double[][] makeDelayEmbeddingVector(double[] data, int k, int startKthPoint, int numEmbeddingVectors) throws Exception { if (startKthPoint < k - 1) { throw new Exception("Start point t=" + startKthPoint + " is too early for a " + k + " length embedding vector"); } if (numEmbeddingVectors + startKthPoint > data.length) { throw new Exception("Too many embedding vectors " + numEmbeddingVectors + " requested for the given startPoint " + startKthPoint + " and time series length " + data.length); } double[][] embeddingVectors = new double[numEmbeddingVectors][k]; for (int t = startKthPoint; t < numEmbeddingVectors + startKthPoint; t++) { for (int i = 0; i < k; i++) { embeddingVectors[t - startKthPoint][i] = data[t - i]; } } return embeddingVectors; } /** * Constructs numEmbeddingVectors embedding vectors of size k for the data, * with embedding delay tau between each time sample for the vectors, * with the first embedding vector having it's last time point at t=startKthPoint * * @param data time series data * @param k embedding length * @param tau embedding delay between each point in the original time series * selected into each embedding vector * @param startKthPoint last time point of the first embedding vector * (i.e. use (k-1)*tau if you want to go from the start) * @param numEmbeddingVectors the number of embedding vectors to return * (i.e. use data.length-(k-1)*tau if you go from the start and want all * of them extracted) * @return a 2D array of k-length embedding vectors. */ public static double[][] makeDelayEmbeddingVector(double[] data, int k, int tau, int startKthPoint, int numEmbeddingVectors) throws Exception { if (startKthPoint < (k - 1) * tau) { throw new Exception("Start point t=" + startKthPoint + " is too early for a " + k + " length embedding vector with delay " + tau); } if (numEmbeddingVectors + startKthPoint > data.length) { throw new Exception("Too many embedding vectors " + numEmbeddingVectors + " requested for the given startPoint " + startKthPoint + " and time series length " + data.length); } double[][] embeddingVectors = new double[numEmbeddingVectors][k]; for (int t = startKthPoint; t < numEmbeddingVectors + startKthPoint; t++) { for (int i = 0; i < k; i++) { embeddingVectors[t - startKthPoint][i] = data[t - i * tau]; } } return embeddingVectors; } /** * Constructs all embedding vectors of k time points for the data, including * all multivariate values at each time point. * Will be data.length - k + 1 of these vectors returned * * @param data 2D time series data (time is first second, second is variable number), * all of which is embedded * @param k embedding length (i.e. number of time extractions for each vector) * @return a 2D array of embedding vectors, which are of length * k x data[0].length. */ public static double[][] makeDelayEmbeddingVector(double[][] data, int k) { try { return makeDelayEmbeddingVector(data, k, k - 1, data.length - k + 1); } catch (Exception e) { // The above call should not throw an Exception, handle here // in a RuntimeException so this method doesn't throw one throw new RuntimeException(e); } } /** * Constructs numEmbeddingVectors embedding vectors of k time points for the data, including * all multivariate values at each time point. * Return only a subset, with the first embedding vector having it's last time point at t=startKthPoint * * @param data 2D time series data (time is first second, second is variable number), * all of which is embedded * @param k embedding length (i.e. number of time extractions for each vector) * @param startKthPoint last time point of the first embedding vector * (i.e. use k-1 if you want to go from the start) * @param numEmbeddingVectors the number of embedding vectors to return * (i.e. use data.length-k+1 if you go from the start and want all * of them extracted) * @return a 2D array of embedding vectors, which are each of length * k x data[0].length. */ public static double[][] makeDelayEmbeddingVector(double[][] data, int k, int startKthPoint, int numEmbeddingVectors) throws Exception { if (startKthPoint < k - 1) { throw new Exception("Start point t=" + startKthPoint + " is too early for a " + k + " length embedding vector"); } if (numEmbeddingVectors + startKthPoint > data.length) { throw new Exception("Too many embedding vectors " + numEmbeddingVectors + " requested for the given startPoint " + startKthPoint + " and time series length " + data.length); } int columns = data[0].length; double[][] embeddingVectors = new double[numEmbeddingVectors][k * columns]; for (int t = startKthPoint; t < numEmbeddingVectors + startKthPoint; t++) { for (int i = 0; i < k; i++) { for (int c = 0; c < columns; c++) { embeddingVectors[t - startKthPoint][i * columns + c] = data[t - i][c]; } } } return embeddingVectors; } /** * Constructs numEmbeddingVectors embedding vectors of k time points for the data, including * all multivariate values at each time point, * with embedding delay tau between each time sample for the vectors, * with the first embedding vector having it's last time point at t=startKthPoint * * @param data 2D time series data (time is first second, second is variable number), * all of which is embedded * @param k embedding length (i.e. number of time extractions for each vector) * @param tau embedding delay between each point in the original time series * selected into each embedding vector * @param startKthPoint last time point of the first embedding vector * (i.e. use k-1 if you want to go from the start) * @param numEmbeddingVectors the number of embedding vectors to return * (i.e. use data.length-k+1 if you go from the start and want all * of them extracted) * @return a 2D array of numEmbeddingVectors embedding vectors, which are each of length * k x data[0].length. */ public static double[][] makeDelayEmbeddingVector(double[][] data, int k, int tau, int startKthPoint, int numEmbeddingVectors) throws Exception { if (startKthPoint < (k - 1) * tau) { throw new Exception("Start point t=" + startKthPoint + " is too early for a " + k + " length embedding vector with delay " + tau); } if (numEmbeddingVectors + startKthPoint > data.length) { throw new Exception("Too many embedding vectors " + numEmbeddingVectors + " requested for the given startPoint " + startKthPoint + " and time series length " + data.length); } int columns = data[0].length; double[][] embeddingVectors = new double[numEmbeddingVectors][k * columns]; for (int t = startKthPoint; t < numEmbeddingVectors + startKthPoint; t++) { for (int i = 0; i < k; i++) { for (int c = 0; c < columns; c++) { embeddingVectors[t - startKthPoint][i * columns + c] = data[t - i * tau][c]; } } } return embeddingVectors; } /** * Constructs numEmbeddingVectors embedding vectors of k time points for a single column of * the data, * with embedding delay tau between each time sample for the vectors, * with the first embedding vector having it's last time point at t=startKthPoint * * @param data 2D time series data (time is first second, second is variable number), * only one particular column of which is embedded * @param column the column index to embed * @param k embedding length (i.e. number of time extractions for each vector) * @param tau embedding delay between each point in the original time series * selected into each embedding vector * @param startKthPoint last time point of the first embedding vector * (i.e. use k-1 if you want to go from the start) * @param numEmbeddingVectors the number of embedding vectors to return * (i.e. use data.length-k+1 if you go from the start and want all * of them extracted) * @return a 2D array of numEmbeddingVectors embedding vectors, which are each of length k. */ public static double[][] makeDelayEmbeddingVector(double[][] data, int column, int k, int tau, int startKthPoint, int numEmbeddingVectors) throws Exception { if (startKthPoint < (k - 1) * tau) { throw new Exception("Start point t=" + startKthPoint + " is too early for a " + k + " length embedding vector with delay " + tau); } if (numEmbeddingVectors + startKthPoint > data.length) { throw new Exception("Too many embedding vectors " + numEmbeddingVectors + " requested for the given startPoint " + startKthPoint + " and time series length " + data.length); } double[][] embeddingVectors = new double[numEmbeddingVectors][k]; for (int t = startKthPoint; t < numEmbeddingVectors + startKthPoint; t++) { for (int i = 0; i < k; i++) { embeddingVectors[t - startKthPoint][i] = data[t - i * tau][column]; } } return embeddingVectors; } }