src/main/java/pt/it/av/tnav/ml/tm/dp/DPWC.java
public static <P extends DPPoint<P>> DPWC buildDPWC(final DPW dpw, final List<Cluster<P>> clusters) {
    List<Cluster<P>> validClusters = new ArrayList<>();

    // Remove empyt clusters
    for (Cluster<P> cluster : clusters) {
      if (cluster.size() > 0) {
        validClusters.add(cluster);
      }
    }

    double[] a = new double[validClusters.size()];

    // Pre-compute affinity
    // Average affinity between data points
    int i = 0;
    for (Cluster<P> cluster : validClusters) {
      for (P point : cluster) {
        a[i] += point.affinity(dpw);
      }
      a[i++] /= (double) cluster.size();
    }

    // Scale affinity
    double max = a[ArrayUtils.max(a)];
    for (i = 0; i < a.length; i++)
      a[i] /= max;

    // Build the DPWC
    List<DPWC.Category> categories = new ArrayList<>();
    i = 0;
    for (Cluster<P> cluster : validClusters) {
      List<DPW.DpDimension> dpDimensions = new ArrayList<>();
      for (P point : cluster) {
        dpDimensions.add(filter(dpw, point));
      }
      categories.add(new DPWC.Category(dpDimensions, a[i++]));
    }

    categories.sort(Collections.reverseOrder());
    return new DPWC(dpw.term(), categories);
  }
/**
   * Returns a {@link DPWC} built using a {@link DPW} and a set of clusters. Uses
   * the average affinity of each cluster as a weight to the similarity metric.
   *
   * @param dpw
   * @param clusters
   * @return
   */
Returns a  DPWC built using a  DPW and a set of clusters. Uses
the average affinity of each cluster as a weight to the similarity metric.

@param dpw
@param clusters
@return
Returns a DPWC built using a DPW and a set of clusters . Uses the average affinity of each cluster as a weight to the similarity metric . @param dpw @param clusters @return
public static <P extends DPPoint<P>> DPWC buildDPWC(final DPW dpw, final List<Cluster<P>> clusters) {
    List<Cluster<P>> validClusters = new ArrayList<>();
    for (Cluster<P> cluster : clusters) {
      if (cluster.size() > 0) {
        validClusters.add(cluster);
      }
    }
    double[] a = new double[validClusters.size()];
    int i = 0;
    for (Cluster<P> cluster : validClusters) {
      for (P point : cluster) {
        a[i] += point.affinity(dpw);
      }
      a[i++] /= (double) cluster.size();
    }
    double max = a[ArrayUtils.max(a)];
    for (i = 0; i < a.length; i++)
      a[i] /= max;
    List<DPWC.Category> categories = new ArrayList<>();
    i = 0;
    for (Cluster<P> cluster : validClusters) {
      List<DPW.DpDimension> dpDimensions = new ArrayList<>();
      for (P point : cluster) {
        dpDimensions.add(filter(dpw, point));
      }
      categories.add(new DPWC.Category(dpDimensions, a[i++]));
    }
    categories.sort(Collections.reverseOrder());
    return new DPWC(dpw.term(), categories);
  }
public static < P extends DPPoint < P > > DPWC buildDPWC ( final DPW dpw , final List < Cluster < P > > clusters ) { List < Cluster < P > > validClusters = new ArrayList < > ( ) ; for ( Cluster < P > cluster : clusters ) { if ( cluster . size ( ) > 0 ) { validClusters . add ( cluster ) ; } } double [ ] a = new double [ validClusters . size ( ) ] ; int i = 0 ; for ( Cluster < P > cluster : validClusters ) { for ( P point : cluster ) { a [ i ] += point . affinity ( dpw ) ; } a [ i ++ ] /= ( double ) cluster . size ( ) ; } double max = a [ ArrayUtils . max ( a ) ] ; for ( i = 0 ; i < a . length ; i ++ ) a [ i ] /= max ; List < DPWC . Category > categories = new ArrayList < > ( ) ; i = 0 ; for ( Cluster < P > cluster : validClusters ) { List < DPW . DpDimension > dpDimensions = new ArrayList < > ( ) ; for ( P point : cluster ) { dpDimensions . add ( filter ( dpw , point ) ) ; } categories . add ( new DPWC . Category ( dpDimensions , a [ i ++ ] ) ) ; } categories . sort ( Collections . reverseOrder ( ) ) ; return new DPWC ( dpw . term ( ) , categories ) ; }
Returns a {@link DPWC} built using a {@link DPW} and a set of clusters.
Returns a { @link DPWC } built using a { @link DPW } and a set of clusters .
// Remove empyt clusters // Pre-compute affinity // Average affinity between data points // Scale affinity // Build the DPWC