Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.apache.mahout.math;
 
Random matrix. Each value is taken from {-1,0,1} with roughly equal probability. Note that by default, the value is determined by a relatively simple hash of the coordinates. Such a hash is not usable where real randomness is required, but suffices nicely for random projection methods. If the simple hash method is not satisfactory, an optional high quality mode is available which uses a murmur hash of the coordinates.
 
 public class RandomTrinaryMatrix extends AbstractMatrix {
   private static final AtomicInteger ID = new AtomicInteger();
   private static final int PRIME1 = 104047;
   private static final int PRIME2 = 101377;
   private static final int PRIME3 = 64661;
   private static final long SCALE = 1L << 32;
 
   private final int seed;
 
   // set this to true to use a high quality hash
   private boolean highQuality = false;
 
   public RandomTrinaryMatrix(int seedint rowsint columnsboolean highQuality) {
     super(rowscolumns);
 
     this. = highQuality;
     this. = seed;
   }
 
   public RandomTrinaryMatrix(int rowsint columns) {
     this(.incrementAndGet(), rowscolumnsfalse);
   }
 
   @Override
   public Matrix assignColumn(int columnVector other) {
     throw new UnsupportedOperationException("Can't assign to read-only matrix");
   }
 
   @Override
   public Matrix assignRow(int rowVector other) {
     throw new UnsupportedOperationException("Can't assign to read-only matrix");
   }

  
Return the value at the given indexes, without checking bounds

Parameters:
row an int row index
column an int column index
Returns:
the double at the index
 
   @Override
   public double getQuick(int rowint column) {
     if () {
       ByteBuffer buf = ByteBuffer.allocate(8);
       buf.putInt(row);
       buf.putInt(column);
       buf.flip();
       return (MurmurHash.hash64A(buf) & ( - 1)) / (double;
     } else {
       // this isn't a fantastic random number generator, but it is just fine for random projections
       return ((((row * ) + column *  + row * column * ) & 8) * 0.25) - 1;
     }
   }


  
Return an empty matrix of the same underlying class as the receiver

Returns:
a Matrix
 
   @Override
   public Matrix like() {
     return new DenseMatrix(rowSize(), columnSize());
   }

  
Returns an empty matrix of the same underlying class as the receiver and of the specified size.

Parameters:
rows the int number of rows
columns the int number of columns
  public Matrix like(int rowsint columns) {
    return new DenseMatrix(rowscolumns);
  }

  
Set the value at the given index, without checking bounds

Parameters:
row an int row index into the receiver
column an int column index into the receiver
value a double value to set
  public void setQuick(int rowint columndouble value) {
    throw new UnsupportedOperationException("Can't assign to read-only matrix");
  }

  
Return the number of values in the recipient

Returns:
an int[2] containing [row, column] count
  public int[] getNumNondefaultElements() {
    throw new UnsupportedOperationException("Can't assign to read-only matrix");
  }

  
Return a new matrix containing the subset of the recipient

Parameters:
offset an int[2] offset into the receiver
size the int[2] size of the desired result
Returns:
a new Matrix that is a view of the original
Throws:
CardinalityException if the length is greater than the cardinality of the receiver
IndexException if the offset is negative or the offset+length is outside of the receiver
  public Matrix viewPart(int[] offsetint[] size) {
    return new MatrixView(thisoffsetsize);
  }
New to GrepCode? Check out our FAQ X