WOLFRAM NOTEBOOK

5.4 Unsupervised Network

5.4.1 Illustrative Example

In[]:=
session=StartExternalSession["Python"]
Out[]=
ExternalSessionObject
System: Python
EvaluationCount:
None
UUID: aaf53c8f-e53e-4593-8e8a-43649c051d74
Test
In[]:=
5+6
Out[]=
11
In[]:=
x={{0.1961`,0.9806`},{-0.1961`,0.9806`},{0.9806`,0.1961`},{0.9806`,-0.1961`},{-0.5812`,-0.8137`},{-0.8137`,-0.5812`}};
In[]:=
p1=ListPlot[x,PlotStyle{PointSize[0.025],RGBColor[1,0,0]},FrameTrue,AxesNone]
Out[]=
In[]:=
<<NeuralNets`
In[]:=
unsup=InitializeUnsupervisedNet[x,3];
In[]:=
{unsup,fitrecord}=UnsupervisedNetFit[x,unsup,50,ReportFrequency5];
In[]:=
UnsupervisedNetDistance[unsup,x]
Out[]=
0.185534
In[]:=
NetPlot[fitrecord,x]
Out[]=
In[]:=
unsup[[1]]
Out[]=
{{0.980144,0.0140458},{-0.703087,-0.69169},{-0.00995935,0.980387}}
In[]:=
import numpy as np
from neupy import algorithms, environment
environment.reproducible()
In[]:=
input_data = np.array([ [0.1961, 0.9806], [-0.1961, 0.9806], [0.9806, 0.1961], [0.9806, -0.1961], [-0.5812, -0.8137], [-0.8137, -0.5812], ])input_data
Out[]=
NumericArray
Type: Real64
Dimensions: {6,2}
In[]:=
Normal[%]
Out[]=
{{0.1961,0.9806},{-0.1961,0.9806},{0.9806,0.1961},{0.9806,-0.1961},{-0.5812,-0.8137},{-0.8137,-0.5812}}
Loading the network algorithm and parametrize the function,
In[]:=
sofmnet = algorithms.SOFM( n_inputs=2, n_outputs=3, step=0.5, show_epoch=100, shuffle_data=True, verbose=True, learning_radius=0, features_grid=(3, 1), )
Main information
[ALGORITHM] SOFM
[OPTION] distance = ['euclid', 'neg_euclid_distance']
[OPTION] features_grid = [3, 1]
[OPTION] grid_type = ['rectangle', 'find_neighbours_on_rect_grid', 'find_step_scaler_on_rect_grid']
[OPTION] learning_radius = 0
[OPTION] n_inputs = 2
[OPTION] n_outputs = 3
[OPTION] reduce_radius_after = 100
[OPTION] reduce_std_after = 100
[OPTION] reduce_step_after = 100
[OPTION] show_epoch = 100
[OPTION] shuffle_data = True
[OPTION] signals = None
[OPTION] std = 1
[OPTION] step = 0.5
[OPTION] verbose = True
[OPTION] weight = Normal(mean=0, std=0.01)
In[]:=
sofmnet.train(input_data,epochs=100)
#1 : [0 ns] train: 0.502381
#100 : [0 ns] train: 0.117317
In[]:=
sofmnet.weight[0:2, :]
Out[]=
NumericArray
Type: Real64
Dimensions: {2,3}
In[]:=
Normal[%]
In[]:=
list1

5.4.2 Iris Data Set

In[]:=
import numpy as np
from sklearn import datasets

from neupy import algorithms, environment
environment.reproducible()
In[]:=
iris = datasets.load_iris()
In[]:=
X=iris.data[:,[2,3]]
y=iris.target
In[]:=
np.savetxt('E:\\dataX.txt',X,fmt='%.2e')
In[]:=
y
In[]:=
sofmnet.train(X,epochs=1500)
In[]:=
sofmnet.weight[0:2, :]
In[]:=
list1

5.4.3 Voronoi Mesh

In[]:=
import numpy as np
from sklearn import datasets

from neupy import algorithms, environment
environment.reproducible()
In[]:=

from numpy import array, matrix
from scipy.io import mmread, mmwrite
In[]:=
caki=mmread('cuki.mtx')
In[]:=
sofmnet.train(caki,epochs=50)
In[]:=
list1
In[]:=
sofmnet.weight[0:2, :]

5.4.4 Robust Regression

In[]:=
caki=mmread('cuki.mtx')
In[]:=
sofmnet.train(caki,epochs=1000)
In[]:=
sofmnet.weight[0:2, :]

5.4.5 Kohonen Map

5.4.6 Fitting Sphere to Point Cloud Data

Wolfram Cloud

You are using a browser not supported by the Wolfram Cloud

Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


I understand and wish to continue anyway »

You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.