/* 
 * MHAP package
 * 
 * This  software is distributed "as is", without any warranty, including 
 * any implied warranty of merchantability or fitness for a particular
 * use. The authors assume no responsibility for, and shall not be liable
 * for, any special, indirect, or consequential damages, or any damages
 * whatsoever, arising out of or in connection with the use of this
 * software.
 * 
 * Copyright (c) 2015 by Konstantin Berlin and Sergey Koren
 * 
 * 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 edu.umd.marbl.mhap.sketch;

import edu.umd.marbl.mhap.math.BasicMath;

public final class CosineDistanceSketch extends AbstractBitSketch<CosineDistanceSketch>
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -6501138603779963996L;

	private static long[] getCuts(double[] vector, int numWords, int seed)
	{
		long[] bitVector = new long[numWords];
		
		for (int word=0; word<numWords; word++)
		{
			long currBitLong = 0b0;
			
			long mask = 0b1;
			for (int bit=0; bit<64; bit++)
			{
				double[] rVec = HashUtils.randomGuassianVector(vector.length, seed+(word+1)*bit);
				double proj = BasicMath.dotProduct(vector, rVec);
				
				if (proj>0.0)
					currBitLong = currBitLong | mask;
				
				mask = mask<<1;
			}
			
			bitVector[word] = currBitLong;
		}
		
		return bitVector;
	}
	
	public CosineDistanceSketch(double[] vector, int numWords, int seed)
	{
		super(getCuts(vector,numWords,seed));
	}

}
