예제 #1
0
 function cluster($k)
 {
     $db = new db();
     $user_dao = new User_dao();
     $user = $user_dao->getAll();
     //get data user
     //create graph
     $graph = new Graph(700, 600);
     //set graph
     $graph->SetScale("linlin");
     $graph->img->SetMargin(70, 50, 50, 50);
     //$graph->SetShadow();
     $graph->title->Set("Friends Twitter Clustering");
     $graph->title->SetFont(FF_ARIAL, FS_NORMAL, 14);
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->title->SetMargin(10);
     $userx = $user->name;
     $graph->subtitle->Set("User: "******" (" . $k . " Kluster)");
     $graph->subtitle->SetFont(FF_FONT1, FS_BOLD);
     //$graph->yaxis->scale->SetAutoMax(1);  //untuk seting max nilai y
     //$graph->xaxis->scale->SetAutoMax(1);  //untuk seting max nilai x
     //
     $following_dao = new Following_dao();
     /* 
     	$data = $following_dao->get();
     	$x = array();
     	$y = array();
     	for($i=0; $i<count($data); $i++){
     		$x[]=$data[$i][0];
     		$y[]=$data[$i][1];	
     	}
     	
     	//format scatterplots data
     	$scatterplots = new ScatterPlot($y, $x); // (Data)
     	$scatterplots->mark->SetType(MARK_FILLEDCIRCLE);
     	$scatterplots->mark->SetFillColor("blue");
     	$scatterplots->mark->SetWidth(4);
     */
     $warna = array("blue", "orange", "green", "purple", "maroon", "pink", "cyan", "violet", "lime", "fuchsia", "maroon", "olive", "navy", "purple", "chocolate", "coral", "lightblue", "orchid", "skyblue", "yellow", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
     //warna untuk cluster
     //data cluster
     for ($i = 0; $i < $k; $i++) {
         $x = array();
         $y = array();
         $data = $following_dao->getByCluster($i + 1);
         //var_dump($data);
         for ($j = 0; $j < count($data); $j++) {
             $x[] = $data[$j][0];
             $y[] = $data[$j][1];
         }
         //var_dump($x);
         $scatterplots[$i] = new ScatterPlot($y, $x);
         $scatterplots[$i]->mark->SetType(MARK_FILLEDCIRCLE);
         if ($warna[$i] == "") {
             $warna[$i] = "gold";
         }
         $scatterplots[$i]->mark->SetFillColor($warna[$i]);
         $scatterplots[$i]->mark->SetWidth(3);
         $graph->Add($scatterplots[$i]);
     }
     // data centroid
     $centroid_dao = new Centroid_dao();
     $data2 = $centroid_dao->get();
     $x2 = array();
     $y2 = array();
     for ($i = 0; $i < count($data2); $i++) {
         $x2[] = $data2[$i][0];
         $y2[] = $data2[$i][1];
     }
     $centroids = new ScatterPlot($y2, $x2);
     // (Centroids)
     $centroids->mark->SetType(MARK_CROSS);
     $centroids->mark->SetFillColor("red");
     $centroids->mark->SetColor("red");
     $centroids->mark->SetWeight(10);
     $centroids->mark->SetWidth(50);
     $centroids->value->SetColor("black");
     // Add plots to graph.
     $graph->Add($centroids);
     //$graph->Add($scatterplots);
     $graph->xaxis->title->Set('Followers Similarity');
     $graph->yaxis->title->Set('Followings Similarity');
     $graph->yaxis->title->SetMargin(10);
     // Display graph
     $graph->Stroke();
 }
예제 #2
0
//var_dump($results);
// echo "<br />";
// var_dump($jitter);
//graph($data, $results, $jitter);
//echo count($data);
//echo count ($results);
$x = array();
$y = array();
//mendapatkan nilai array untuk similarity_followers sbg x dan similarity_following sbg y
for ($i = 0; $i < count($data); $i++) {
    $x[] = $data[$i][0];
    $y[] = $data[$i][1];
}
$x2 = array();
$y2 = array();
$centroid_dao = new Centroid_dao();
$centroid_dao->deleteAll();
//menghapus data centroid lama
$i = 0;
$cluster = array();
//inisialisasi array cluster
for ($i = 0; $i < $k; $i++) {
    //if(!isset($results[0][$i][0])){$results[0][$i][0]="";}
    //if(!isset($results[0][$i][1])){$results[0][$i][1]="";}
    $x2[] = array($results[0][$i][0], $results[0][$i][1]);
    //mendapatkan nilai dari msing-masing centroid
    //[0] menandakan array pertama dari $result yang berarti centroid. [$i] menandakan array ke-i dari centroid. [0] dan [1] menandakan nilai x dan y dari centroid
    //$y2[]=$results[0][$i][1];
    $centroid = new Centroid();
    //buat objek centroid
    $centroid->centx = $results[0][$i][0];
예제 #3
0
<?php

session_start();
require_once 'twitteroauth/twitteroauth.php';
require_once 'config/config.php';
require_once 'config/db.php';
require_once 'lib/user.php';
require_once 'lib/follower.php';
require_once 'lib/following.php';
require_once 'lib/follower2.php';
require_once 'lib/following2.php';
require_once 'lib/centroid.php';
$db = new db();
$user_dao = new User_dao();
$user = $user_dao->getAll();
$Centroid_Dao = new Centroid_dao();
$centroid = $Centroid_Dao->getAll();
$Following_Dao = new Following_Dao();
$similarity = $Following_Dao->get();
//$cluster = $Following_dao->get
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>MyTwit</title>
<style type="text/css">
<!--
body {
	background-image: url(images/bg.gif);
}