Name | Vorname | Matrikelnummer | Datum |
Alt | Tobias | 282385 | 09.01.2016 |
In [82]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
import math
from skimage import io
from skimage.transform import resize
from random import shuffle
from scipy import stats
import matplotlib.cm as cm
In [83]:
def createCluster1(ypos,numberOfData,clusterDistance,varianz):
#sigma = sqrt(clusterBright) # mean and standard deviation
mu = clusterDistance #loc Paramter -> Abstand
sigma = sqrt(varianz) #scale Parameter -> Clusterbreite
sizeOfData = numberOfData #Anzahl Daten
cluster = np.random.normal(ypos+mu, sigma, (sizeOfData, 2))
return cluster
In [84]:
def createCluster2(ypos,numberOfData,clusterDistance,varianz):
#sigma = sqrt(clusterBright) # mean and standard deviation
mu = clusterDistance #loc Paramter -> Abstand
sigma = sqrt(varianz) #scale Parameter -> Clusterbreite
sizeOfData = numberOfData #Anzahl Daten
cluster = np.random.normal(ypos-mu, sigma, (sizeOfData, 2))
return cluster
In [85]:
#Erzeugen der Daten (wie gewünscht einstellbar)
#---------------------------------------------------------------------------
varianz = 0.5 #Clusterbreite
numberOfData = 200 #Anzahl neuer Datenpunkte pro Cluster
mean= 1.5 #Abstand
ypos = 0 #y-Achsen-Verschiebung
Cluster1 = createCluster1(ypos,numberOfData,mean,varianz)
Cluster2 = createCluster2(ypos,numberOfData,mean,varianz)
print shape(Cluster1)
print shape(Cluster2)
In [86]:
#Erzeugen des zugehörigen Labelvektor mit den Werten ±1
#-------------------------------------------------------------------
labelvector1 = np.ones((numberOfData, 1)) * -1
labelvector2 = np.ones((numberOfData, 1)) * 1
print shape(labelvector1)
print shape(labelvector2)
labels = np.vstack((labelvector1, labelvector2))
print shape(labels)
In [107]:
#Mittelwert der Cluster
meanC1 = np.mean(Cluster1, axis=0)
meanC2 = np.mean(Cluster2, axis=0)
print meanC1
print meanC2
In [106]:
#Standardabweichung
stdC1 = np.std(Cluster1, axis=0)
stdC2 = np.std(Cluster2, axis=0)
print stdC1
print stdC2
#Vergleich zu Sigma
sigma = sqrt(varianz)
print 'Sigma im Vergleich: ',sigma
In [123]:
#A-Prioriwahrscheinlichkeit der beiden Cluster ausrechnen
len_cluster1 = Cluster1.shape[0]
len_cluster2 = Cluster2.shape[0]
total_len = len_cluster1 + len_cluster2
apriori_cluster1 = len_cluster1/total_len
apriori_cluster2 = len_cluster2/total_len
print apriori_cluster1, apriori_cluster2
#Muss 0.5 rauskommen liegt evtl. an meiner python version 2.6
#mit set_printoptions(precision=2) gehts auch nicht
In [ ]: