类内方差

@param docs
@param centroid

@return
9275
private float calculateClusterQuality (ArrayList<Instance> docs,
			HashSparseVector centroid) {
		float quality = 0.0f;
		HashSparseVector c = centroid;

		for (int i = 0; i < docs.size(); ++i) {
			Instance doc = docs.get(i);

			quality += c.distanceEuclidean((HashSparseVector) doc.getData());
		}

		return quality;
	}
229149
public PointExpression<Point> centroid() {
        if (centroid == null) {
            centroid = GeometryExpressions.pointOperation(SpatialOps.CENTROID, mixin);
        }
        return centroid;
    }
582371
public Content getDocLink(LinkInfoImpl.Kind context, MemberDoc doc, String label) {
        return getDocLink(context, doc.containingClass(), doc,
                new StringContent(label));
    }
116619
public IndexDoc getDoc(String field, int docId) {
    if (fieldReferences.containsKey(field)) {
      FieldReferences fr = fieldReferences.get(field);
      try {
        IndexInput inIndexDocId = indexInputList.get("indexDocId");
        ArrayList<MtasTreeHit<?>> list = CodecSearchTree.searchMtasTree(docId,
            inIndexDocId, fr.refIndexDocId, fr.refIndexDoc);
        if (list.size() == 1) {
          return new IndexDoc(list.get(0).ref);
        }
      } catch (IOException e) {
        log.debug(e);
        return null;
      }
    }
    return null;
  }
1230072
def get_element_centroids(self):
        
        centroids = np.vstack((
            np.mean(self.grid['x'], axis=1), np.mean(self.grid['z'], axis=1)
        )).T

        return centroids
334123
public final CellName clusteringKey(Document document) {
        String string = document.get(FIELD_NAME);
        ByteBuffer bb = ByteBufferUtils.fromString(string);
        return cellNameType.cellFromByteBuffer(bb);
    }
279044
protected static Map<Integer, Integer> createCentroidMappings(int centroidNum,
            List<CentroidMapping> allDistance)
    {
        Set<Integer> baseSet = new HashSet<>();
        Set<Integer> targetSet = new HashSet<>();
        Map<Integer, Integer> resultMapping = new TreeMap<>();
        int mappingNum = 0;

        // 算出したユークリッド処理リストをソートして使用
        for (CentroidMapping targetDistance : allDistance)
        {
            // 既にマッピングに使用されている場合は省略する。
            if (baseSet.contains(targetDistance.getBaseIndex())
                    || targetSet.contains(targetDistance.getTargetIndex()))
            {
                continue;
            }

            baseSet.add(targetDistance.getBaseIndex());
            targetSet.add(targetDistance.getTargetIndex());
            resultMapping.put(targetDistance.getBaseIndex(), targetDistance.getTargetIndex());
            mappingNum++;

            // マッピングが必要数確保できた時点でマッピングを終了
            if (mappingNum >= centroidNum)
            {
                break;
            }
        }

        return resultMapping;
    }
1182645
def centroid(coo):
    
    return list(map(np.mean, (([c[0] for c in coo]), ([c[1] for c in coo]), ([c[2] for c in coo]))))
1008568
public static final Atom getCentroid(Atom[] atomSet){

		// if we don't catch this case, the centroid returned is (NaN,NaN,NaN), which can cause lots of problems down the line
		if (atomSet.length==0)
			throw new IllegalArgumentException("Atom array has length 0, can't calculate centroid!");


		double[] coords = new double[3];

		coords[0] = 0;
		coords[1] = 0;
		coords[2] = 0 ;

		for (Atom a : atomSet) {
			coords[0] += a.getX();
			coords[1] += a.getY();
			coords[2] += a.getZ();
		}

		int n = atomSet.length;
		coords[0] = coords[0] / n;
		coords[1] = coords[1] / n;
		coords[2] = coords[2] / n;

		Atom vec = new AtomImpl();
		vec.setCoords(coords);
		return vec;

	}
1133448
function centroidOf(points, dimension) {
    var centroid = new Float32Array(dimension);
    for (var i = 0; i < centroid.length; i++) {
      var sum = 0;
      var count = 0;
      for (var pointIndex = 0; pointIndex < points.length; pointIndex++) {
        var p = points[pointIndex];
        var point = p.getPoint();
        var val = point.getValue(i);
        if (!isNaN(val)) {
          sum += val;
          count++;
        }
      }
      centroid[i] = (sum / count);
    }
    return new PointWrapper(morpheus.VectorUtil.arrayAsVector(centroid));
  }
1297965
@Override
  public int nextDoc() throws IOException {
    docId = NO_MORE_DOCS;
    currentStartPosition = NO_MORE_POSITIONS;
    currentEndPosition = NO_MORE_POSITIONS;
    return docId;
  }
22728
public static Map<Identity, JsonNode> getDocumentIdMap(List<JsonNode> list, List<String> identityFields) {
        Map<Identity, JsonNode> map = new HashMap<>();
        if (list != null) {
            LOGGER.debug("Getting doc IDs for {} docs, fields={}", list.size(), identityFields);
            for (JsonNode node : list) {
                Identity id = new Identity(node, identityFields);
                LOGGER.debug("ID={}", id);
                map.put(id, node);
            }
        }
        return map;
    }
812707
void section(int nclusters)
    {
        if (size() < nclusters)
            return;

        sectioned_clusters_ = new ArrayList<Cluster<K>>(nclusters);
        List<Document> centroids = new ArrayList<Document>(nclusters);
        // choose_randomly(nclusters, centroids);
        choose_smartly(nclusters, centroids);
        for (int i = 0; i < centroids.size(); i++)
        {
            Cluster<K> cluster = new Cluster<K>();
            sectioned_clusters_.add(cluster);
        }

        for (Document<K> d : documents_)
        {
            double max_similarity = -1.0;
            int max_index = 0;
            for (int j = 0; j < centroids.size(); j++)
            {
                double similarity = SparseVector.inner_product(d.feature(), centroids.get(j).feature());
                if (max_similarity < similarity)
                {
                    max_similarity = similarity;
                    max_index = j;
                }
            }
            sectioned_clusters_.get(max_index).add_document(d);
        }
    }
893320
public Document cmisDocument( CmisObject cmisObject ) {
        org.apache.chemistry.opencmis.client.api.Document doc = (org.apache.chemistry.opencmis.client.api.Document)cmisObject;
        DocumentWriter writer = newDocument(ObjectId.toString(ObjectId.Type.OBJECT, doc.getId()));

        ObjectType objectType = cmisObject.getType();
        if (objectType.isBaseType()) {
            writer.setPrimaryType(NodeType.NT_FILE);
        } else {
            writer.setPrimaryType(objectType.getId());
        }

        List<Folder> parents = doc.getParents();
        ArrayList<String> parentIds = new ArrayList<String>();
        for (Folder f : parents) {
            parentIds.add(ObjectId.toString(ObjectId.Type.OBJECT, f.getId()));
        }

        writer.setParents(parentIds);
        writer.addMixinType(NodeType.MIX_REFERENCEABLE);
        writer.addMixinType(NodeType.MIX_LAST_MODIFIED);

        // document specific property conversation
        cmisProperties(doc, writer);
        writer.addChild(ObjectId.toString(ObjectId.Type.CONTENT, doc.getId()), JcrConstants.JCR_CONTENT);

        writer.addMixinType("mode:accessControllable");
        writer.addChild(ObjectId.toString(ObjectId.Type.ACL, cmisObject.getId()), "mode:acl");
        
        return writer.document();
    }
505789
@Override
  public void printProbsDocument(List<IN> document) {

    Pair<int[][][], int[]> p = documentToDataAndLabels(document);
    int[][][] data = p.first();

    // FactorTable[] factorTables =
    // CRFLogConditionalObjectiveFunction.getCalibratedCliqueTree(weights, data,
    // labelIndices, classIndex.size());
    CRFCliqueTree cliqueTree = CRFCliqueTree.getCalibratedCliqueTree(weights, data, labelIndices, classIndex.size(),
        classIndex, flags.backgroundSymbol);

    // for (int i = 0; i < factorTables.length; i++) {
    for (int i = 0; i < cliqueTree.length(); i++) {
      IN wi = document.get(i);
      System.out.print(wi.get(CoreAnnotations.TextAnnotation.class) + '\t');
      for (Iterator<String> iter = classIndex.iterator(); iter.hasNext();) {
        String label = iter.next();
        int index = classIndex.indexOf(label);
        // double prob = Math.pow(Math.E, factorTables[i].logProbEnd(index));
        double prob = cliqueTree.prob(i, index);
        System.out.print(label + '=' + prob);
        if (iter.hasNext()) {
          System.out.print("\t");
        } else {
          System.out.print("\n");
        }
      }
    }
  }
446860
public static final Atom[] centerAtoms(Atom[] atomSet, Atom centroid)
			throws StructureException {

		Atom shiftVector = getCenterVector(atomSet, centroid);

		Atom[] newAtoms = new AtomImpl[atomSet.length];

		for (int i =0 ; i < atomSet.length; i++){
			Atom a = atomSet[i];
			Atom n = add(a,shiftVector);
			newAtoms[i] = n ;
		}
		return newAtoms;
	}
1032862
def rm_centroid_on(corner)
      c = @grom.rm_crop_area(corner)
      p = @mack.rm_patch(c, @grom.rm_blur, @grom.rm_dilate)
      # byebug
      n = NPatch.new(p, c.w, c.h)
      cx, cy, sd = n.centroid
      st = (cx < 2) or (cy < 2) or (cy > c.h-2) or (cx > c.w-2)
      status = st ? :edgy : :ok
      return {x: cx+c.x, y: cy+c.y, sd: sd, status: status}
    end