gt: 				for(double number : timeSeries.data){
context: package ca.pfv.spmf.algorithms.timeseries.sax;
  
  /* This file is copyright (c) 2008-2016 Philippe Fournier-Viger
  * 
  * This file is part of the SPMF DATA MINING SOFTWARE
  * (http://www.philippe-fournier-viger.com/spmf).
  * 
  * SPMF 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.
  * 
  * SPMF 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
  * SPMF. If not, see <http://www.gnu.org/licenses/>.
  */
  
  
  import java.io.IOException;
  import java.util.Arrays;
  import java.util.List;
  
  import ca.pfv.spmf.algorithms.timeseries.TimeSeries;
  import ca.pfv.spmf.algorithms.timeseries.paa.AlgoPiecewiseAggregateApproximation;
  import ca.pfv.spmf.tools.MemoryLogger;
  
  /**
   * An implementation of the SAX algorithm to convert a time series to a sequence of symbols.<br/><br/>
   * 
   * It is based on the description in:<br/><br/>
   * 
   * Lin, Jessica, et al. "Experiencing SAX: a novel symbolic representation of time series. <br/>
   * Data Mining and knowledge discovery 15.2 (2007): 107-144.<br/>
   * 
   * @author Philippe Fournier-Viger, 2016
   * @see SAXSymbol
   * @see AlgoPiecewiseAggregateApproximation
   */
  public class AlgoSAX {
   
  	/** the time the algorithm started */
  	long startTimestamp = 0; 
  	/** the time the algorithm terminated */
  	long endTimestamp = 0;  
  	
  	/** This program will execute in DEBUG MODE if this variable is true */
  	boolean DEBUG_MODE = false;
  	
  	/** The symbols created for the last converted time series */
  	SAXSymbol[] symbols;
  	
  	/** the last symbol that was used (to make sure that we don't give the same symbol to several time series **/
  	int lastSymbol = 0;
  	
  	/** the number of time series that was processed during the last execution of the algorithm **/
  	int timeSeriesCount = 0;
  	
  	/** the minimum number of symbols allowed by this sax implementation*/
  	public static final int MIN_NUMBER_OF_SYMBOLS = 2;
  	
  	/** the maximum number of symbols allowed by this sax implementation*/
  	public static final int MAX_NUMBER_OF_SYMBOLS = 30;
  		
  	/**
  	 * Default constructor
  	 */
  	public AlgoSAX() {
  	}
  
  	/**
  	 * Run the algorithm SAX algorithm on a single time series
  	 * @param timeSeries a time series 
  	 * @param numberOfSegments the number of segments ( > 1)
  	 * @param numberOfSymbols  the number of symbols 
  	 * @param deactivatePAA set this parameter to true to deactivate PAA before applying SAX
  	 * @return the sax representation of the time series (an array of Symbol objects)
  	 * @throws IOException exception if error while writing the file
  	 */
  	public SAXSymbol[] runAlgorithm(TimeSeries timeSeries, int numberOfSegments, int numberOfSymbols, boolean deactivatePAA) throws IOException {
  		// check some error for parameters
  		if(timeSeries.data.length < numberOfSegments){
  			throw new IllegalArgumentException(" The number of segments should be less than or equal to the number of data points in the time series");
  		}
  		
  		// check some error for parameters
  		if(numberOfSegments < 2){
  			throw new IllegalArgumentException(" This implementation of SAX only support a number of segments > 1");
  		}
  		
  		if(numberOfSymbols < MIN_NUMBER_OF_SYMBOLS || numberOfSymbols > MAX_NUMBER_OF_SYMBOLS){
  			throw new IllegalArgumentException(" This implementation of SAX only support a number of symbols between"+ MIN_NUMBER_OF_SYMBOLS + " to " + MAX_NUMBER_OF_SYMBOLS);
  		}
  		
  		// reset memory logger
  		MemoryLogger.getInstance().reset();
  		
  		// record the start time of the algorithm
  		startTimestamp = System.currentTimeMillis();
  		
  		// reset the lastSymbol 
  		lastSymbol = 0;
  
  		// IF in debug mode
  		if(DEBUG_MODE){
  			// Print the time series
  			System.out.println(" Time series: " + timeSeries);
  		}
  		
  		//========================  CALCULATE THE MINIMUM, MAXIMUM, AVERAGE, VARIANCE AND STDDEV OF THIS TIME SERIES =======================
  		double min = Double.MAX_VALUE;
  		double max = -Double.MAX_VALUE;
  		double average =  0;
  		double variance = 0;
  		double stdev = 0;
  		
  		// Calculate the minimum maximum and average
  		for(double number : timeSeries.data){
  			if(number > max){
  				max = number;
  			}
  			if(number < min){
  				min = number;
  			}
  			average += number;
  		}
  		
  		average /= timeSeries.data.length;
  		
  		// Calculate variance
  		for(double number : timeSeries.data){
  			variance += Math.pow(average - number, 2);
  		}
  		variance = variance / timeSeries.data.length;
  		
  		// Calculate the standard deviation
  		stdev = Math.sqrt(variance);				
  		
  		// IF in debug mode
  		if(DEBUG_MODE){
  			System.out.println(" --- Calculating statistics ---");
  			System.out.println(" Min = " + min + " Max = " + max + " Average = " + average + 
  					System.lineSeparator() + " Standard deviation = " + stdev + " Variance = " + variance);
  		}
  		
  		//======================== CREATE THE PAA (Piecewise aggregate approximation) of this time series============
  		// Create an array to store the P.A.A.
  		AlgoPiecewiseAggregateApproximation paaAlgo = new AlgoPiecewiseAggregateApproximation();
  		TimeSeries piecewiseTransformedData;
  		if(deactivatePAA){
  			piecewiseTransformedData = timeSeries;
  		}else{
  			piecewiseTransformedData = paaAlgo.runAlgorithm(timeSeries, numberOfSegments);
  		}
  		
  
  		//======================  CREATE THE SYMBOLS ===============================
  		// create the symbols
  		symbols = createSAXSymbols(numberOfSymbols, average, stdev);
  		
  		//======================  TRANSFORM P.A.A  to the SAW REPRESENTATION ===============================
  		SAXSymbol[] saxSequence = transformPAAtoSAXRepresentation(piecewiseTransformedData.data, symbols);
  				
  		// There is only one time series
  		timeSeriesCount = 1;
  		
  		// check the memory usage again and close the file.
  		MemoryLogger.getInstance().checkMemory();
  		// record end time
  		endTimestamp = System.currentTimeMillis();
  
  		return saxSequence;
  	}
  	
  
  	/**
  	 * Run the SAX algorithm on multiple time series
  	 * @param multipleTimeSeries a set of time series represented by a two-dimensional double array
  	 * @param numberOfSegments the number of segments ( > 1)
  	 * @param numberOfSymbols  the number of symbols 
  	 * @param deactivatePAA Set this variable to true to deactivate the PAA part of the SAX algorithm.
  	 * @return the sax representation of the time series (an array of Symbol objects)
  	 * @throws IOException exception if error while writing the file
  	 */
  	public SAXSymbol[][] runAlgorithm(List<TimeSeries> multipleTimeSeries, int numberOfSegments,
  			int numberOfSymbols, boolean deactivatePAA) throws IOException {
  			
  			// check some error for parameters
  			if(numberOfSegments < 2){
  				throw new IllegalArgumentException(" This implementation of SAX only support a number of segments > 1");
  			}
  			
  			if(numberOfSymbols < 2 || numberOfSymbols >20){
  				throw new IllegalArgumentException(" This implementation of SAX only support a number of symbols between 2 to 20");
  			}
  			
  			// reset memory logger
  			MemoryLogger.getInstance().reset();
  			
  			// record the start time of the algorithm
  			startTimestamp = System.currentTimeMillis();
  			
  			// reset the lastSymbol 
  			lastSymbol = 0;
  
  			//========================  CALCULATE THE MINIMUM, MAXIMUM, AVERAGE, VARIANCE AND STDDEV OF THIS TIME SERIES =======================
  			double min = Double.MAX_VALUE;
  			double max = -Double.MAX_VALUE;
  			double average =  0;
  			double variance = 0;
  			double stdev = 0;
  			
  			double dataPointCount = 0;
  			
  			// Calculate the minimdum maximum and average
  			for(TimeSeries timeSeries : multipleTimeSeries){
  