2015-04-05 49 views
-1

似乎通過JavaScript進行機器學習處於起步階段,因爲幾乎沒有任何圖書館適合其他計算智能和可視化。樹狀圖:figue.js(聚類)輸出,以適應可視化

我使用figue.js庫,並通過以下希望輸出結果:

http://www.meccanismocomplesso.org/en/dendrogramma-d3-parte1/ http://www.meccanismocomplesso.org/en/dendrogramma-d3-parte2/ http://www.meccanismocomplesso.org/en/dendrogramma-d3-parte3/

這是它要求:

{ 
    "name": "root", "y" : 0, 
    "children": [ 
    { 
    "name": "parent A", "y" : 30, 
    "children": [ 
     {"name": "child A1", "y" : 100}, 
     {"name": "child A2", "y" : 100}, 
     {"name": "child A3", "y" : 100} 
    ] 
    },{ 
    "name": "parent B", "y" : 76, 
    "children": [ 
     {"name": "child B1", "y" : 100}, 
     {"name": "child B2", "y" : 100} // <--- number at the end is the ultrametric distance 
    ] 
    } 
    ] 
} 

這是figue。 js給我(當然是不同的,所有的開發者都這麼做......):

{ 
    "label": -1, 
    "left": { 
     "label": "Point 1", 
     "left": null, 
     "right": null, 
     "dist": 0, 
     "centroid": [ 
      13.0406203, 
      55.606759100000005 
     ], 
     "size": 1, 
     "depth": 0 
    }, 
    "right": { 
     "label": -1, 
     "left": { 
      "label": -1, 
      "left": { 
       "label": -1, 
       "left": { 
        "label": "Point 2", 
        "left": null, 
        "right": null, 
        "dist": 0, 
        "centroid": [ 
         13.0403852, 
         55.6066934 
        ], 
        "size": 1, 
        "depth": 0 
       }, 
       "right": { 
        "label": "Point 5", 
        "left": null, 
        "right": null, 
        "dist": 0, 
        "centroid": [ 
         13.0404121, 
         55.6066418 
        ], 
        "size": 1, 
        "depth": 0 
       }, 
       "dist": 0.00005819080683319214, 
       "centroid": [ 
        13.04039865, 
        55.606667599999994 
       ], 
       "size": 2, 
       "depth": 1 
      }, 
      "right": { 
       "label": "Point 3", 
       "left": null, 
       "right": null, 
       "dist": 0, 
       "centroid": [ 
        13.0404818, 
        55.606629700000006 
       ], 
       "size": 1, 
       "depth": 0 
      }, 
      "dist": 0.00007074249076717127, // <--- ultrametric distance 
      "centroid": [ 
       13.040426366666667, 
       55.60665496666667 
      ], 
      "size": 3, 
      "depth": 2 
     }, 
     "right": { 
      "label": "Point 4", 
      "left": null, 
      "right": null, 
      "dist": 0, 
      "centroid": [ 
       13.0405408, 
       55.6066934 
      ], 
      "size": 1, 
      "depth": 0 
     }, 
     "dist": 0.00008682562985036432, 
     "centroid": [ 
      13.040454975000001, 
      55.606664574999996 
     ], 
     "size": 4, 
     "depth": 3 
    }, 
    "dist": 0.00010313457228779574, 
    "centroid": [ 
     13.040488040000003, 
     55.606683479999994 
    ], 
    "size": 5, 
    "depth": 4 
} 

我可以說這是很難解決的。還是有人知道任何可能編譯結構的庫?

+0

所以,你要尋找的figue.js輸出之間的適配器,使其在本地d3.js工作? – 2015-04-05 14:53:43

+0

@JaredFarrish事實上,我現在正在寫一篇,但它不起作用。適配器是這個詞,謝謝。 – 2015-04-05 14:55:28

+0

我沒有看到任何可能工作的東西,它本身並不是一個完整的包(如OpenRefine)或某些R來源的數據適配器。我看到其他人也問過同樣的問題;如果你開發一個解決方案,我會建議提供這個答案,以便其他人可以受益。 – 2015-04-05 15:40:40

回答

1
var root = figue.figue.agglomerate(figueLabels, figueVectors, figue.figue.EUCLIDIAN_DISTANCE, figue.figue.SINGLE_LINKAGE); 

// the above code is from figue.js, I have however modified the library so that it is module and works in nodejs 

// the code below is the adapter 

function recursive(json) { 
    var str; 
    if (json.left !== null || json.right !== null) { 
     str = { 
      name: '', 
      y: json.dist, 
      children: [] 
     }; 
     if (json.left !== null) { 
      str.children.push(recursive(json.left)); 
     } 
     if (json.right !== null) { 
      str.children.push(recursive(json.right)); 
     } 
    } else { 

     str = { 
      name: json.label, 
      y: json.dist 
     }; 
    } 
    return str; 
} 

var json = recursive(root); 

// there we go, now we can use the json variable as an argument for the visualization 

console.log(JSON.stringify(json)); 

以下是查看結果!

enter image description here