Examples of DoubleVector


Examples of edu.ucla.sspace.vector.DoubleVector

        for (int r = 0; r < base.rows(); ++r)
            for (int c = 0; c < base.columns(); ++c)
                assertEquals(base.get(r, c) * SCALE.get(r), scaled.get(r, c), .0001);

        for (int r = 0; r < base.rows(); ++r) {
            DoubleVector v = scaled.getRowVector(r);
            assertEquals(base.columns(), v.length());
            for (int c = 0; c < base.columns(); ++c)
                assertEquals(base.get(r, c) * SCALE.get(r), v.get(c), .0001);
        }
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j)
                matrix.set(i, j, i*j);
        }
       
        DoubleVector row5 = matrix.getRowVector(5);
        for (int j = 0; j < 10; ++j)
            assertEquals(5 * j, row5.get(j), 0.001d);
        assertEquals(10, row5.length());
        row5.set(5, -1d);
        assertEquals(-1, row5.get(5), 0.001d);
        assertEquals(-1, matrix.get(5,5), 0.001d);
    }  
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

        for (int r = 0; r < base.rows(); ++r)
            for (int c = 0; c < base.columns(); ++c)
                assertEquals(base.get(r, c) * SCALE.get(r), scaled.get(r, c), .0001);

        for (int r = 0; r < base.rows(); ++r) {
            DoubleVector v = scaled.getRowVector(r);
            assertEquals(base.columns(), v.length());
            for (int c = 0; c < base.columns(); ++c)
                assertEquals(base.get(r, c) * SCALE.get(r), v.get(c), .0001);
        }
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.DoubleVector

     * between newly nerged clusters.
     */
    public Assignments cluster(Matrix m, int numClusters, Properties props) {
        Matrix adj = new SymmetricMatrix(m.rows(), m.rows());
        for (int r = 0; r < m.rows(); ++r) {
            DoubleVector v = m.getRowVector(r);
            for (int c = r+1; c < m.rows(); ++c)
                adj.set(r,c, simFunc.sim(v, m.getRowVector(c)));
        }
        return clusterAdjacencyMatrix(adj, method, numClusters);
    }
View Full Code Here

Examples of moa.core.DoubleVector

        double Bm = em / (1.0 - em);
        return Math.log(1.0 / Bm);
    }

    public double[] getVotesForInstance(Instance inst) {
      DoubleVector combinedVote = new DoubleVector();
      try {
      lock.acquire();
          for(ClassifierInstance c : ensemble){
            double memberWeight = getEnsembleMemberWeight(c);
            if (memberWeight > 0.0) {
                  DoubleVector vote = new DoubleVector(c.getClassifier().getVotesForInstance(inst));
                  if (vote.sumOfValues() > 0.0) {
                      vote.normalize();
                      vote.scaleValues(memberWeight);
                      combinedVote.addValues(vote);
                  }
              } else {
                  break;
              }
View Full Code Here

Examples of org.apache.hama.commons.math.DoubleVector

      }
    }

    double relativeError = 0;
    for (int i = 0; i < instances.length; ++i) {
      DoubleVector test = new DenseDoubleVector(instances[i]);
      double expected = test.get(test.getDimension() - 1);
      test = test.slice(test.getDimension() - 1);
      double actual = regression.getOutput(test).get(0);
      relativeError += Math.abs((expected - actual) / expected);
    }

    relativeError /= instances.length;
View Full Code Here

Examples of org.apache.hama.ml.math.DoubleVector

    double[] trainingFeature = Arrays.copyOfRange(trainingVec, 0,
        this.layerSizeArray[0]);
    double[] trainingLabels = Arrays.copyOfRange(trainingVec,
        this.layerSizeArray[0], trainingVec.length);

    DoubleVector trainingFeatureVec = new DenseDoubleVector(trainingFeature);
    List<double[]> outputCache = this.outputInternal(trainingFeatureVec);

    // calculate the delta of output layer
    double[] delta = new double[this.layerSizeArray[this.layerSizeArray.length - 1]];
    double[] outputLayerOutput = outputCache.get(outputCache.size() - 1);
View Full Code Here

Examples of org.neo4j.graphalgo.impl.util.MatrixUtil.DoubleVector

                }
            }
            // Orthogonalize
            for ( int j = 0; j < localIterations; ++j )
            {
                DoubleVector qj = qMatrix.getRow( j );
                // vector product
                double product = 0;
                for ( int i = 0; i < nodes.size(); ++i )
                {
                    Double d1 = newValues.get( nodes.get( i ) );
                    Double d2 = qj.get( i );
                    if ( d1 != null && d2 != null )
                    {
                        product += d1 * d2;
                    }
                }
                hMatrix.set( j, localIterations - 1, product );
                if ( product != 0.0 )
                {
                    // vector subtraction
                    for ( int i = 0; i < nodes.size(); ++i )
                    {
                        Node node = nodes.get( i );
                        Double value = newValues.get( node );
                        if ( value == null )
                        {
                            value = 0.0;
                        }
                        Double qValue = qj.get( i );
                        if ( qValue != null )
                        {
                            newValues.put( node, value - product * qValue );
                        }
                    }
                }
            }
            double normalizeFactor = normalize( newValues );
            values = newValues;
            DoubleVector qVector = new DoubleVector();
            for ( int i = 0; i < nodes.size(); ++i )
            {
                qVector.set( i, newValues.get( nodes.get( i ) ) );
            }
            qMatrix.setRow( localIterations, qVector );
            if ( normalizeFactor == 0.0 || localIterations >= nodeSet.size()
                || localIterations >= iterations )
            {
                break;
            }
            hMatrix.set( localIterations, localIterations - 1, normalizeFactor );
            ++localIterations;
        }
        // employ the power method to find eigenvector to h
        Random random = new Random( System.currentTimeMillis() );
        DoubleVector vector = new DoubleVector();
        for ( int i = 0; i < nodeSet.size(); ++i )
        {
            vector.set( i, random.nextDouble() );
        }
        MatrixUtil.normalize( vector );
        boolean powerDone = false;
        int its = 0;
        double powerPrecision = 0.1;
        while ( !powerDone )
        {
            DoubleVector newVector = MatrixUtil.multiply( hMatrix, vector );
            MatrixUtil.normalize( newVector );
            powerDone = true;
            for ( Integer index : vector.getIndices() )
            {
                if ( newVector.get( index ) == null )
                {
                    continue;
                }
                double factor = Math.abs( newVector.get( index )
                    / vector.get( index ) );
                if ( factor - powerPrecision > 1.0
                    || factor + powerPrecision < 1.0 )
                {
                    powerDone = false;
                    break;
                }
            }
            vector = newVector;
            ++its;
            if ( its > 100 )
            {
                break;
            }
        }
        // multiply q and vector to get a ritz vector
        DoubleVector ritzVector = new DoubleVector();
        for ( int r = 0; r < nodeSet.size(); ++r )
        {
            for ( int c = 0; c < localIterations; ++c )
            {
                ritzVector.incrementValue( r, vector.get( c )
                    * qMatrix.get( c, r ) );
            }
        }
        for ( int i = 0; i < nodeSet.size(); ++i )
        {
            values.put( nodes.get( i ), ritzVector.get( i ) );
        }
        normalize( values );
        return localIterations;
    }
View Full Code Here

Examples of org.renjin.sexp.DoubleVector

  }
 
  @Test
  public void invokeFunction() throws ScriptException, NoSuchMethodException {
    engine.eval("f <- function(x) sqrt(x)");
    DoubleVector result = (DoubleVector)invocableEngine.invokeFunction("f", 4);
   
    assertThat(result.length(), equalTo(1));
    assertThat(result.get(0), equalTo(2d));
  }
View Full Code Here

Examples of weka.core.matrix.DoubleVector

    X.lsqrSelection( Y, pvt, 1 );
    X.positiveDiagonal( Y, pvt );
   
    PaceMatrix sol = (PaceMatrix) Y.clone();
    X.rsolve( sol, pvt, pvt.size() );
    DoubleVector r = Y.getColumn( pvt.size(), n-1, 0);
    double sde = Math.sqrt(r.sum2() / r.size());
   
    DoubleVector aHat = Y.getColumn( 0, pvt.size()-1, 0).times( 1./sde );

    DoubleVector aTilde = null;
    switch( paceEstimator) {
    case ebEstimator:
    case nestedEstimator:
    case subsetEstimator:
      NormalMixture d = new NormalMixture();
      d.fit( aHat, MixtureDistribution.NNMMethod );
      if( paceEstimator == ebEstimator )
  aTilde = d.empiricalBayesEstimate( aHat );
      else if( paceEstimator == ebEstimator )
  aTilde = d.subsetEstimate( aHat );
      else aTilde = d.nestedEstimate( aHat );
      break;
    case pace2Estimator:
    case pace4Estimator:
    case pace6Estimator:
      DoubleVector AHat = aHat.square();
      ChisqMixture dc = new ChisqMixture();
      dc.fit( AHat, MixtureDistribution.NNMMethod );
      DoubleVector ATilde;
      if( paceEstimator == pace6Estimator )
  ATilde = dc.pace6( AHat );
      else if( paceEstimator == pace2Estimator )
  ATilde = dc.pace2( AHat );
      else ATilde = dc.pace4( AHat );
      aTilde = ATilde.sqrt().times( aHat.sign() );
      break;
    case olsEstimator:
      aTilde = aHat.copy();
      break;
    case aicEstimator:
    case bicEstimator:
    case ricEstimator:
    case olscEstimator:
      if(paceEstimator == aicEstimator) olscThreshold = 2;
      else if(paceEstimator == bicEstimator) olscThreshold = Math.log( n );
      else if(paceEstimator == ricEstimator) olscThreshold = 2*Math.log( kr );
      aTilde = aHat.copy();
      for( int i = 0; i < aTilde.size(); i++ )
  if( Math.abs(aTilde.get(i)) < Math.sqrt(olscThreshold) )
    aTilde.set(i, 0);
    }
    PaceMatrix YTilde = new PaceMatrix((new PaceMatrix(aTilde)).times( sde ));
    X.rsolve( YTilde, pvt, pvt.size() );
    DoubleVector betaTilde = YTilde.getColumn(0).unpivoting( pvt, kr );
   
    return betaTilde.getArrayCopy();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.