Package Jama

Examples of Jama.Matrix


    IndexSearcher is = new IndexSearcher(dir);
    //IndexSearcher is = lis.getIndexSearcher();
    is.setSimilarity(new MySimilarity());
    ir = is.getIndexReader();
    long time = System.currentTimeMillis();
    Matrix matrix = new Matrix(ir.numDocs(), ir.numDocs());
    int nz = 0;
    for(int i=0;i<ir.numDocs();i++) {
      System.out.println(i);
      //nz++;
      matrix.set(i, i, 1.0);
      Query q = myMoreLikeThisQuery(ir, i);
      //time = System.currentTimeMillis();
      Hits h = is.search(q);
      //System.out.println(System.currentTimeMillis() - time);
      //time = System.currentTimeMillis();
      Iterator iterator = h.iterator();
      while(iterator.hasNext()) {
        Hit hit = (Hit)iterator.next();
        int id = hit.getId();
        float score = hit.getScore();
        //if(score < 0.025) break;
        if(i != id) {
          //matrix.set(i, id, score);
          matrix.set(i, id, matrix.get(i, id) + score/2);
          matrix.set(id, i, matrix.get(id, i) + score/2);
          //nz++;
        }
        //System.out.println(i + "\t" + hit.getId() + "\t" + hit.getScore());
      }
      //System.out.println(System.currentTimeMillis() - time);
      //System.out.println(((double)h.length()) / ir.numDocs());
     
    }
    for(int i=0;i<matrix.getColumnDimension();i++) {
      for(int j=0;j<matrix.getRowDimension();j++) {
        if(matrix.get(i, j) != 0.0) nz++;
      }
    }
    System.out.println(System.currentTimeMillis() - time);
    time = System.currentTimeMillis();
    //matrix.eig();
    System.out.println(System.currentTimeMillis() - time);
    System.out.println(nz);
   
   
   
    int newnz = 0;
    System.out.println(matrix.getColumnDimension() + " " + matrix.getRowDimension() + " " + nz);
    for(int i=0;i<matrix.getColumnDimension();i++) {
      int nonzero = 0;
      for(int j=0;j<matrix.getRowDimension();j++) {
        if(matrix.get(i, j) != 0.0) nonzero++;
      }
      System.out.println(nonzero);
      for(int j=0;j<matrix.getRowDimension();j++) {
        if(matrix.get(i, j) != 0.0) System.out.println(j + " " + matrix.get(i, j));
      }
      newnz += nonzero;
    }
    System.out.println(newnz);
  }
View Full Code Here


        svdh.set(fno, i, wv.get(feature));
      }
    }
    System.out.println("Harness ready...");
    svdh.svd(10);
    Matrix lm = svdh.getUt().transpose();
    System.out.println(lm.getRowDimension());
    System.out.println(lm.getColumnDimension());
    System.out.println(termNo);
    System.out.println(featureNo);
    double [] svals = svdh.getS();
    if(true) {
      for(int i=0;i<svals.length;i++) {
        System.out.println(svals[i]);
        for(int j=0;j<lm.getRowDimension();j++) {
          lm.set(j, i, lm.get(j, i) * svals[i]);
        }
      }     
    }

    for(int tn=0;tn<termNo;tn++) {
      System.out.println(terms.get(tn));
      Map<String,Double> cosines = new HashMap<String,Double>();
      for(int i=0;i<terms.size();i++) {
        double termScore = 0.0;
        double otherTermScore = 0.0;
        double product = 0.0;
       
        for(int j=0;j<svals.length;j++) {
          double tVal = lm.get(tn,j);
          double otVal = lm.get(i,j);
          termScore += tVal * tVal;
          otherTermScore += otVal * otVal;
          product += tVal * otVal;
        }
        double cosine = product / (Math.sqrt(termScore) * Math.sqrt(otherTermScore));
 
View Full Code Here

     * @param data данные для анализа
     */
    public static void singularDecomposition(SSAData data) {
        double inclosureMatrix[][] = data.getInclosureMatrix();
        double transp[][] = transpositionMatrix(inclosureMatrix);
        Matrix S = new Matrix(inclosureMatrix).times(new Matrix(transp));
        //int d = new Matrix(inclosureMatrix).rank(); //ранг матрицы вложений
        EigenvalueDecomposition decomposition = new EigenvalueDecomposition(S);
        Matrix eigenvalue = decomposition.getD();   //матрица с собственными значениями
        Matrix eigenvec = decomposition.getV();     //матрица собственных векторов
        List<Double> eigenvalueList = new ArrayList<Double>();
        //формируем набор собственных значений, стоящих на диагонали
        for (int i = 0; i < eigenvalue.getRowDimension(); i++) {
            for (int j = 0; j < eigenvalue.getRowDimension(); j++) {
                if (i == j) {
                    eigenvalueList.add(eigenvalue.get(i, j));
                }
            }
        }
        Comparator comparator = Collections.reverseOrder();
        /*
         * собственные значения должны быть в убывающем порядке, поэтому
         * сортируем их в обратном порядке (изначально значения в возрастающем
         * порядке)
         */
        Collections.sort(eigenvalueList, comparator);
        data.setEigenValueList(eigenvalueList);
        double sumValueList = 0;
        List<Double> percentList;
        List<Double> accruePercentList;
        for (int i = 0; i < data.getEigenValueList().size(); i++) {
            sumValueList = sumValueList + data.getEigenValueList().get(i);
        }
        //формирование процентов собственных чисел и накопленных процентов
        percentList = new ArrayList<Double>();
        accruePercentList = new ArrayList<Double>();
        double accruePercent = 0;
        for (int i = 0; i < data.getEigenValueList().size(); i++) {
            percentList.add(data.getEigenValueList().get(i) / sumValueList * 100);
            accruePercent += percentList.get(i);
            accruePercentList.add(accruePercent);
        }
        data.setAccruePercentList(accruePercentList);
        data.setPercentList(percentList);

        int size = eigenvec.getColumnDimension();
        Matrix V[] = new Matrix[size];
        Matrix U[] = new Matrix[size];
        Matrix X[] = new Matrix[size]; //элементарные матрицы сингулярного разложения
        ArrayList listSeries = new ArrayList();
        for (int j = 0; j < eigenvec.getColumnDimension(); j++) {
            double uVec[][] = new double[size][1];
            ArrayList series = new ArrayList();
            for (int k = 0; k < eigenvec.getRowDimension(); k++) {
                /*
                 * векторы должны соответствовать собственным числа (!), поэтому
                 * начинаем с последнего собственного вектора
                 */
                uVec[k][0] = eigenvec.get(k, eigenvec.getColumnDimension() - j - 1);
                series.add(uVec[k][0]);
            }
            listSeries.add(series);
            U[j] = new Matrix(uVec);
            V[j] = new Matrix(transp).times(U[j]);
        }
        data.setEigenVectors(listSeries);
        for (int i = 0; i < V.length; i++) {
            for (int j = 0; j < V[i].getRowDimension(); j++) {
                for (int k = 0; k < V[i].getColumnDimension(); k++) {
View Full Code Here

     *
     * @param model модель JList (список групп)
     * @param data данные для анализа
     */
    public static void grouping(DefaultListModel model, SSAData data) {
        Matrix grouX[] = new Matrix[model.getSize()];
        for (int i = 0; i < model.getSize(); i++) {
            GroupListObject obj = (GroupListObject) model.get(i);
            for (int j = 0; j < obj.getGroups().size(); j++) {
                UnselectListObject unselect = (UnselectListObject) obj.getGroups().get(j);
                if (j == 0) {
View Full Code Here

    public static void averagedCovariance(SSAData data) {
        double avg;
        double K = data.getTimeSeries().size() - data.getL() + 1; //количество векторов вложения
        List<Double> covarianceList = new ArrayList<Double>();
        double transp[][] = transpositionMatrix(data.getInclosureMatrix());
        Matrix S = new Matrix(data.getInclosureMatrix()).times(new Matrix(transp));
        S = S.times(1.0 / K); //ковариационная матрица
        int size = S.getColumnDimension();
        int N = size + size - 1;
        int n;
        for (int k = 0; k < N; k++) {
            if ((k % 2) == 0) {
                if (k >= 0 && k < size) {
                    avg = 0;
                    n = 0;
                    for (int m = 0; m <= k; m++) {
                        avg += S.get(m, size - 1 - (k - m));
                        n++;
                    }
                    avg = avg / (n);
                    covarianceList.add(avg);
                }
                if (k >= size && k < N) {
                    avg = 0;
                    n = 0;
                    for (int m = k - size + 1; m <= N - size; m++) {
                        avg += S.get(m, size - 1 - (k - m));
                        n++;
                    }
                    avg = avg / (n);
                    covarianceList.add(avg);
                }
View Full Code Here

        } else {
          p0 = new double[stations.size()];
          p0[0] = 1; // Assumes that all jobs enters in first station
        }
        try {
          Matrix b = new Matrix(p0, 1);
          Matrix P = new Matrix(buildProbabilityMatrix(stations, input, classKeys.get(cl), res));
          // V = (P-eye(3))' \ (-b') where \ is "mldivide"
          Matrix V = P.minus(Matrix.identity(stations.size(), stations.size())).solveTranspose(b.uminus());
          vis = V.getColumnPackedCopy();
        } catch (Exception e) {
          // Matrix is singular
          res.add("Cannot compute correctly visits for " + output.getClassNames()[cl] + " as" + " network thopology was badly specified");
        }

      } else {
        // Closed class, system is indefinded, so sets visits to reference station to
        // 1 and builds a smaller P matrix
        stations = new Vector<Object>(input.getStationKeysNoSourceSink());
        // Finds reference station
        Object refStat = input.getClassRefStation(classKeys.get(cl));
        if (refStat == null) {
          refStat = stations.get(0);
          res.add("Reference station for " + output.getClassNames()[cl] + " was " + "not set. " + input.getStationName(refStat)
              + " was chosen.");
        }

        // Sets visits to reference station (if allowed) to 1
        if (stationKeys.contains(refStat)) {
          visits[stationKeys.lastIndexOf(refStat)][cl] = 1;
        }
        // Removes reference station from stations vector and computes p0
        stations.remove(refStat);
        double[] p0 = getRoutingProbability(refStat, classKeys.get(cl), input, stations, res);

        try {
          Matrix b = new Matrix(p0, 1);
          Matrix P = new Matrix(buildProbabilityMatrix(stations, input, classKeys.get(cl), res));
          // V = (P-eye(3))' \ (-b') where \ is "mldivide"
          Matrix V = P.minus(Matrix.identity(stations.size(), stations.size())).solveTranspose(b.uminus());
          vis = V.getColumnPackedCopy();
        } catch (Exception e) {
          // Matrix is singular
          res.add("Cannot compute correctly visits for " + output.getClassNames()[cl] + " as" + " network thopology was badly specified");
        }
      }
View Full Code Here

  /**
       * computes the variance of the extimator of the variance
       */
  protected double calcExtimatorVar(int K, int polyOrder) {
    Matrix X = new Matrix(K, polyOrder + 1);
    Matrix Xt;
    Matrix square;
    for (int i = 0; i < K; i++) {
      for (int j = 0; j <= polyOrder; j++) {
        X.set(i, j, (Math.pow((4 * ((double) i + 1) - 1) / (2 * (double) K), j)));
      }
    }
    Xt = X.transpose();
    square = Xt.times(X);
    square = square.inverse();
    //System.out.println("calcConst "+square.get(0,0));
    return (.645 * square.get(0, 0));
  }
View Full Code Here

        { v2x, 0, 0, -v1x, 0, 0, 0, 0, 0 }, { 0, v2y, 0, 0, -v1y, 0, 0, 0, 0 }, { 0, 0, v2z, 0, 0, -v1z, 0, 0, 0 },
        { 0, 0, 0, v3x, 0, 0, -v2x, 0, 0 }, { 0, 0, 0, 0, v3y, 0, 0, -v2y, 0 }, { 0, 0, 0, 0, 0, v3z, 0, 0, -v2z } };

    double[][] arrayb = { { 1 }, { 1 }, { 1 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, };

    Matrix A = new Matrix(arraya);
    Matrix b = new Matrix(arrayb);
    Matrix x = A.solve(b);

    Sector3D out = new Sector3D(x.get(0, 0), x.get(1, 0), x.get(2, 0), x.get(3, 0), x.get(4, 0), x.get(5, 0), x.get(6, 0), x.get(7, 0), x.get(8,
        0), 3, v1, v2, v3);

    return out;
  }
View Full Code Here

        { 0, 0, v2z, 0, 0, -v1z }, { 0, 0, 0, 0, 0, 1 } };

    double[][] arrayb = { { 1 }, { 1 }, { 0 }, { 0 }, { 0 }, { 0 } };
    //t double[][] arrayb ={{1,1,1,0,0,0,0,0,0}};

    Matrix A = new Matrix(arraya);
    Matrix b = new Matrix(arrayb);
    Matrix x = A.solve(b);

    BetaVertex vf1 = new BetaVertex(x.get(0, 0), x.get(1, 0), x.get(2, 0));
    BetaVertex vf2 = new BetaVertex(x.get(3, 0), x.get(4, 0), x.get(5, 0));

    //BetaVertex v3 = new BetaVertex();
    //BetaVertex v4 = new BetaVertex();

    Sector3D out = new Sector3D(vf1, vf2, v1, v2, 2, st1, st2);
View Full Code Here

        { 0, 0, v2z, 0, 0, -v1z }, { 0, 0, 0, 1, 0, 0 } };

    double[][] arrayb = { { 1 }, { 1 }, { 0 }, { 0 }, { 0 }, { 0 } };
    //t double[][] arrayb ={{1,1,1,0,0,0,0,0,0}};

    Matrix A = new Matrix(arraya);
    Matrix b = new Matrix(arrayb);
    Matrix x = A.solve(b);

    BetaVertex vf1 = new BetaVertex(x.get(0, 0), x.get(1, 0), x.get(2, 0));
    BetaVertex vf2 = new BetaVertex(x.get(3, 0), x.get(4, 0), x.get(5, 0));

    //BetaVertex v3 = new BetaVertex();
    //BetaVertex v4 = new BetaVertex();

    Sector3D out = new Sector3D(vf1, vf2, v1, v2, 2, st1, st2);
View Full Code Here

TOP

Related Classes of Jama.Matrix

Copyright © 2018 www.massapicom. 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.