Unverified Commit 9b85be3b authored by Saman Nia's avatar Saman Nia Committed by GitHub
Browse files

Final

parent 4a8aa74b
......@@ -7,6 +7,13 @@
"Author: Saman Paidar Nia"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All resources are listed at the bottom of the page."
]
},
{
"cell_type": "code",
"execution_count": 1,
......@@ -49,14 +56,18 @@
"metadata": {},
"outputs": [],
"source": [
"class Cosine_Similarity(Similarity_Normalization):\n",
"class Correlation_Similarity(Similarity_Normalization):\n",
" def get_matrix(self, X):\n",
" X = normalize(X, axis=0)\n",
" x = squareform(pdist(X, 'cosine'))\n",
" x = np.dot(LA.matrix_power(np.diag(np.sum(x, 0)), -1), x)\n",
" x = np.apply_along_axis(self.normalization, 1, x)\n",
" np.fill_diagonal(x, 0.)\n",
" return x"
" X = pdist(X, 'correlation')\n",
" X = squareform(X)\n",
" S = np.sum(X, 0)\n",
" D = np.diag(S)\n",
" D = LA.matrix_power(D, -1)\n",
" Y = np.dot(D, X)\n",
" Y = np.apply_along_axis(self.normalization, 1, Y)\n",
" np.fill_diagonal(Y, 0.)\n",
" return Y"
]
},
{
......@@ -65,14 +76,18 @@
"metadata": {},
"outputs": [],
"source": [
"class Correlation_Similarity(Similarity_Normalization):\n",
"class Cosine_Similarity(Similarity_Normalization):\n",
" def get_matrix(self, X):\n",
" X = normalize(X, axis=0)\n",
" x = squareform(pdist(X, 'correlation'))\n",
" x = np.dot(LA.matrix_power(np.diag(np.sum(x, 0)), -1), x)\n",
" x = np.apply_along_axis(self.normalization, 1, x)\n",
" np.fill_diagonal(x, 0.)\n",
" return x"
" X = pdist(X, 'cosine')\n",
" X = squareform(X)\n",
" S = np.sum(X, 0)\n",
" D = np.diag(S)\n",
" D = LA.matrix_power(D, -1)\n",
" Y = np.dot(D, X)\n",
" Y = np.apply_along_axis(self.normalization, 1, Y)\n",
" np.fill_diagonal(Y, 0.)\n",
" return Y"
]
},
{
......@@ -306,7 +321,7 @@
"beta1 = 0.9 #------------------------------ The decay rate 1. \n",
"beta2 = 0.999 #---------------------------- The decay rate 2.\n",
"learning_rate = (beta1/n_input) #---------- The learning rate.\n",
"n_epoch = math.ceil(n_nodes/n_layers) #------------------------ The stop learning point.\n",
"n_epoch = math.ceil(n_nodes/n_layers) #---- The stop learning point.\n",
"n_batch = math.ceil(sqrt(sqrt(n_input))) #- Number of selection data in per step.\n",
"n_backpro = math.ceil(n_input/n_batch) #--- Number of Backpro in per epoch.\n",
"n_cluster = 3 #---------------------------- Number of clusters.\n",
......@@ -375,9 +390,9 @@
" miniData, _ = trainSet_correlation.next_batch(n_batch)\n",
" _, new_cost = sess.run([train_optimizer,cost], feed_dict={x: miniData,\n",
" phase_train: True}) \n",
" #------------------------- End of the Optimization ---------------------------\n",
" #------------------------- End of the Optimization ------------------------------\n",
" epoch += 1\n",
" # Save the results after per (Size of input / n_layers) epochs. \n",
" # Save the results after per (number of epoch / number of layers) epochs. \n",
" if epoch % n_diplay == 0 or epoch == n_epoch:\n",
" # Getting embedded codes and running K-Means on them.\n",
" ae_codes_cor = sess.run(code, feed_dict={x: trainSet_correlation.whole_dataset()[0],\n",
......@@ -437,9 +452,9 @@
" miniData, _ = trainSet_cosine.next_batch(n_batch)\n",
" _, new_cost = sess.run([train_optimizer,cost], feed_dict={x: miniData,\n",
" phase_train: True}) \n",
" #------------------------- End of the Optimization ---------------------------\n",
" #------------------------- End of the Optimization ------------------------------\n",
" epoch += 1\n",
" # Save the results after per (Size of input / n_layers) epochs. \n",
" # Save the results after per (number of epoch / number of layers) epochs. \n",
" if epoch % n_diplay == 0 or epoch == n_epoch:\n",
" # Getting embedded codes and running K-Means on them.\n",
" ae_codes_cos = sess.run(code, feed_dict={x: trainSet_cosine.whole_dataset()[0],\n",
......@@ -621,11 +636,53 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
"source": [
"____________________________________________________________________________________________________________________________"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"____________________________________________________________________________________________________________________________"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Refrences:\n",
"\n",
"SciPy (the library) Jones E, Oliphant E, Peterson P, et al. SciPy: Open Source Scientific Tools for Python, 2001-, http://www.scipy.org/ [Online; accessed 2018-02-20]. Here’s an example of a BibTeX entry:\n",
"\n",
"@Misc{, author = {Eric Jones and Travis Oliphant and Pearu Peterson and others}, title = {{SciPy}: Open source scientific tools for {Python}}, year = {2001--}, url = \"http://www.scipy.org/\", note = {[Online; accessed\n",
"\n",
"NumPy & SciPy:\n",
"\n",
"Stéfan van der Walt, S. Chris Colbert and Gaël Varoquaux. The NumPy Array: A Structure for Efficient Numerical Computation, Computing in Science & Engineering, 13, 22-30 (2011), DOI:10.1109/MCSE.2011.37 (publisher link)\n",
"\n",
"IPython:\n",
"\n",
"Fernando Pérez and Brian E. Granger. IPython: A System for Interactive Scientific Computing, Computing in Science & Engineering, 9, 21-29 (2007), DOI:10.1109/MCSE.2007.53 (publisher link)\n",
"\n",
"Matplotlib:\n",
"\n",
"John D. Hunter. Matplotlib: A 2D Graphics Environment, Computing in Science & Engineering, 9, 90-95 (2007), DOI:10.1109/MCSE.2007.55 (publisher link)\n",
"\n",
"Scikit-learn:\n",
"\n",
"Fabian Pedregosa, Gaël Varoquaux, Alexandre Gramfort, Vincent Michel, Bertrand Thirion, Olivier Grisel, Mathieu Blondel, Peter Prettenhofer, Ron Weiss, Vincent Dubourg, Jake Vanderplas, Alexandre Passos, David Cournapeau, Matthieu Brucher, Matthieu Perrot, Édouard Duchesnay. Scikit-learn: Machine Learning in Python, Journal of Machine Learning Research, 12, 2825-2830 (2011) (publisher link)\n",
"\n",
"TensorFlow:\n",
"\n",
"@misc{tensorflow2015-whitepaper, title={ {TensorFlow}: Large-Scale Machine Learning on Heterogeneous Systems}, url={https://www.tensorflow.org/}, note={Software available from tensorflow.org},\n",
"\n",
"Jupyter Notebooks:\n",
"\n",
"@conference{Kluyver:2016aa, Author = {Thomas Kluyver and Benjamin Ragan-Kelley and Fernando P{\\'e}rez and Brian Granger and Matthias Bussonnier and Jonathan Frederic and Kyle Kelley and Jessica Hamrick and Jason Grout and Sylvain Corlay and Paul Ivanov and Dami{\\'a}n Avila and Safia Abdalla and Carol Willing}, Booktitle = {Positioning and Power in Academic Publishing: Players, Agents and Agendas}, Editor = {F. Loizides and B. Schmidt}, Organization = {IOS Press}, Pages = {87 - 90}, Title = {Jupyter Notebooks -- a publishing format for reproducible computational workflows}, Year = {2016}}"
]
}
],
"metadata": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment