Java Code Examples for org.apache.mahout.math.VectorWritable#get()
The following examples show how to use
org.apache.mahout.math.VectorWritable#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: 1000021_CDbwEvaluator_t.java From coming with MIT License | 6 votes |
private void setStDev(int cI) { List<VectorWritable> repPts = representativePoints.get(cI); //if (repPts == null) { // System.out.println(); //} int s0 = 0; Vector s1 = null; Vector s2 = null; for (VectorWritable vw : repPts) { s0++; Vector v = vw.get(); s1 = s1 == null ? v.clone() : s1.plus(v); s2 = s2 == null ? v.times(v) : s2.plus(v.times(v)); } if (s0 > 1) { Vector std = s2.times(s0).minus(s1.times(s1)).assign(new SquareRootFunction()).divide(s0); double d = std.zSum() / std.size(); //System.out.println("stDev[" + cI + "]=" + d); stDevs.put(cI, d); } }
Example 2
Source File: 1000021_CDbwEvaluator_s.java From coming with MIT License | 6 votes |
private void setStDev(int cI) { List<VectorWritable> repPts = representativePoints.get(cI); //if (repPts == null) { // System.out.println(); //} int s0 = 0; Vector s1 = null; Vector s2 = null; for (VectorWritable vw : repPts) { s0++; Vector v = vw.get(); s1 = s1 == null ? v.clone() : s1.plus(v); s2 = s2 == null ? v.times(v) : s2.plus(v.times(v)); } Vector std = s2.times(s0).minus(s1.times(s1)).assign(new SquareRootFunction()).divide(s0); double d = std.zSum() / std.size(); //System.out.println("stDev[" + cI + "]=" + d); stDevs.put(cI, d); }
Example 3
Source File: Step32.java From recsys-offline with Apache License 2.0 | 6 votes |
public void map(VarLongWritable key,VectorWritable value,Context context) throws IOException, InterruptedException{ long userID=key.get(); Vector userVector=value.get(); Iterator<Vector.Element> it=userVector.nonZeroes().iterator(); IntWritable itemi=new IntWritable(); while(it.hasNext()){ Vector.Element e=it.next(); int itemIndex=e.index(); float preferenceValue=(float)e.get(); itemi.set(itemIndex); context.write(itemi, new VectorOrPrefWritable(userID,preferenceValue)); System.out.println("item :"+itemi+",userand val:"+userID+","+preferenceValue); } }
Example 4
Source File: AdmmIterationMapper.java From laser with Apache License 2.0 | 5 votes |
protected void map(Text key, VectorWritable value, Context context) throws IOException, InterruptedException { // ignore per clustering records if (key.toString().contains("|clustering")) { return; } Vector v = value.get(); if (addIntercept) { v.set(0, 1.0); } inputSplitData.add(v); }
Example 5
Source File: Step5.java From recsys-offline with Apache License 2.0 | 5 votes |
public void reduce(VarLongWritable key, Iterable<VectorWritable> values,Context context) throws IOException, InterruptedException{ Vector partial=null; for(VectorWritable v:values){ partial=partial==null?v.get():partial.plus(v.get()); } context.write(key, new VectorWritable(partial)); System.err.println("userid:"+key.toString()+",vecotr:"+partial);// here also should be the same as my paper's result }
Example 6
Source File: Step5.java From recsys-offline with Apache License 2.0 | 5 votes |
public void reduce(VarLongWritable key, Iterable<VectorWritable> values,Context context) throws IOException, InterruptedException{ int userID=(int)key.get(); Vector rev=null; for(VectorWritable vec:values){ rev=rev==null? vec.get():rev.plus(vec.get()); } Queue<RecommendedItem>topItems=new PriorityQueue<RecommendedItem>( recommendationsPerUser+1, Collections.reverseOrder(ByValueRecommendedItemComparator.getInstance()) ); Iterator<Vector.Element>recommendationVectorIterator= rev.nonZeroes().iterator(); while(recommendationVectorIterator.hasNext()){ Vector.Element e=recommendationVectorIterator.next(); int index=e.index(); System.out.println("Vecotr.element.indxe:"+index); // test here find the index is item id or not ** test result : index is item if(!hasItem(userID,String.valueOf(index))){ float value=(float) e.get(); if(topItems.size()<recommendationsPerUser){ // here only set index topItems.add(new GenericRecommendedItem(index,value)); }else if(value>topItems.peek().getValue()){ topItems.add(new GenericRecommendedItem(index,value)); topItems.poll(); } } } List<RecommendedItem>recom=new ArrayList<RecommendedItem>(topItems.size()); recom.addAll(topItems); Collections.sort(recom,ByValueRecommendedItemComparator.getInstance()); context.write(key, new RecommendedItemsWritable(recom)); }
Example 7
Source File: 1000021_CDbwEvaluator_t.java From coming with MIT License | 4 votes |
public double interClusterDensity() { double sum = 0.0; for (Map.Entry<Integer, List<VectorWritable>> entry1 : representativePoints.entrySet()) { Integer cI = entry1.getKey(); List<VectorWritable> repI = entry1.getValue(); double stDevI = getStdev(cI); for (Map.Entry<Integer, List<VectorWritable>> entry2 : representativePoints.entrySet()) { Integer cJ = entry2.getKey(); if (cI.equals(cJ)) { continue; } List<VectorWritable> repJ = entry2.getValue(); double minDistance = Double.MAX_VALUE; Vector uIJ = null; for (VectorWritable aRepI : repI) { for (VectorWritable aRepJ : repJ) { Vector vI = aRepI.get(); Vector vJ = aRepJ.get(); double distance = measure.distance(vI, vJ); if (distance < minDistance) { minDistance = distance; uIJ = vI.plus(vJ).divide(2); } } } double stDevJ = getStdev(cJ); double interDensity = uIJ == null ? 0 : interDensity(uIJ, cI, cJ); double stdSum = stDevI + stDevJ; double density = 0.0; if (stdSum > 0.0) { density = minDistance * interDensity / stdSum; } log.debug("minDistance[" + cI + "," + cJ + "]=" + minDistance); log.debug("stDev[" + cI + "]=" + stDevI); log.debug("stDev[" + cJ + "]=" + stDevJ); log.debug("interDensity[" + cI + "," + cJ + "]=" + interDensity); log.debug("density[" + cI + "," + cJ + "]=" + density); sum += density; } } //System.out.println("interClusterDensity=" + sum); return sum; }
Example 8
Source File: 1000021_CDbwEvaluator_s.java From coming with MIT License | 4 votes |
public double interClusterDensity() { double sum = 0.0; for (Map.Entry<Integer, List<VectorWritable>> entry1 : representativePoints.entrySet()) { Integer cI = entry1.getKey(); List<VectorWritable> repI = entry1.getValue(); double stDevI = stDevs.get(cI); for (Map.Entry<Integer, List<VectorWritable>> entry2 : representativePoints.entrySet()) { Integer cJ = entry2.getKey(); if (cI.equals(cJ)) { continue; } List<VectorWritable> repJ = entry2.getValue(); double minDistance = Double.MAX_VALUE; Vector uIJ = null; for (VectorWritable aRepI : repI) { for (VectorWritable aRepJ : repJ) { Vector vI = aRepI.get(); Vector vJ = aRepJ.get(); double distance = measure.distance(vI, vJ); if (distance < minDistance) { minDistance = distance; uIJ = vI.plus(vJ).divide(2); } } } double stDevJ = stDevs.get(cJ); double interDensity = interDensity(uIJ, cI, cJ); double stdSum = stDevI + stDevJ; double density = 0.0; if (stdSum > 0.0) { density = minDistance * interDensity / stdSum; } // Use a logger //if (false) { // System.out.println("minDistance[" + cI + "," + cJ + "]=" + minDistance); // System.out.println("stDev[" + cI + "]=" + stDevI); // System.out.println("stDev[" + cJ + "]=" + stDevJ); // System.out.println("interDensity[" + cI + "," + cJ + "]=" + interDensity); // System.out.println("density[" + cI + "," + cJ + "]=" + density); // System.out.println(); //} sum += density; } } //System.out.println("interClusterDensity=" + sum); return sum; }