All Downloads are FREE. Search and download functionalities are using the official Maven repository.

datasets.VectorDouble Maven / Gradle / Ivy

The newest version!
package datasets;

import base.CommonConstants;

import datastructs.IVector;
import datastructs.RowType;
import maths.VectorOperations;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.apache.commons.math3.stat.descriptive.rank.Median;
import stats.Statistics;
import tech.tablesaw.api.DoubleColumn;
import tech.tablesaw.api.Row;
import tech.tablesaw.api.Table;

import java.util.List;

/**
 * Implements a Vector that holds doubles
 */

public class VectorDouble implements IVector {


    /**
     * Creates an vector with initial capacity of 10
     */
    public VectorDouble(){
        this.data = new VectorStorage<>(10, 0.0);
    }

    /**
     * Creates a vector of given size with entries initialized to val
     */
    public VectorDouble(int size, double val){

        this.data = new VectorStorage<>(size, val);
        this.stats_ = new Statistics();
    }

    /**
     * Create a vector from the given double values
     */
    public VectorDouble(Double... data){

        this.data = new VectorStorage<>(data);
        this.stats_ = new Statistics();
    }

    /**
     * Create a vector from the given double values
     */
    public VectorDouble(List data){

        this.data = new VectorStorage(data);
        this.stats_ = new Statistics();
    }

    /**
     * Creates a vector of given size with entries initialized to 0.0
     */
    public VectorDouble(int size){
        this(size, 0.0);
    }


    /**
     * Create a vector from another vector i.e. copy constructor
     */
    public VectorDouble(IVector data){
        this(data.size(), 0.0);
        this.set(data);
    }

    /**
     * Create from the given Table and the given column name
     */
    public VectorDouble(Table table, String columnName){
        this(table.doubleColumn(columnName));
    }

    /**
     * Create a vector from the given DoubleColumn
     */
    public VectorDouble(DoubleColumn column){
        this.data = new VectorStorage<>(column.size(), 0.0);
        this.set(column);
        this.stats_ = new Statistics();
    }

    @Override
    public final RowType.Type getType(){return RowType.Type.DOUBLE_VECTOR; }

    /**
     * Returns true if the vector is empty
     */
    @Override
    public boolean empty(){
        return this.data.isEmpty();
    }

    /**
     * Build a new instance of this class
     */
    @Override
    public IVector create(int size){
        return new VectorDouble(size, 0.0);
    }

    /**
     * Build a new instance of this class
     */
    @Override
    public IVector create( Double... value){
        return new VectorDouble(value);
    }

    @Override
    public IVector create(){return new VectorDouble();}

    /**
      * Resize the vector
     */
    @Override
    public final void resize(int size){

        if(data == null){
            this.data.create(size, 0.0);
        }
        else{

            // nothing to do here if sizes are the same
            if(size == data.size()){
                return;
            }

            VectorStorage newVec = new VectorStorage(size, 0.0);

            if(size > data.size()){

                for(int i=0; i= data.size()){
            throw  new IllegalArgumentException("Invalid index. index given not in [0, "+data.size()+")");
        }

        this.data.set(i, val);
        this.falsifyCalculations();
    }

    /**
     * Set the  entries to val
     */
    @Override
    public final void set(IVector values){

        if(values.size() != this.size()){
            throw  new IllegalArgumentException("Invalid Vector size: "+ values.size() + " != " + this.size());
        }

        for(int i=0; i getRawData(){
        return data.getRawData();
    }


    /**
     * Compute the sample statistics
     */
    protected void compute_sample_statistics() {

        double[] arrayData = new double[this.data.size()];

        for(int i=0; i data = null;

    /**
     * Object that holds the calculated statistics
     */
    protected Statistics stats_;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy