Saturday, April 28, 2018

Continuing Review of Rescal.py


In rescal.py [1]:

Line 155:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.spmatrix.tocoo.html


Line 165 - 166:

S = S + X[i].T
S = S + X[i]

https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html

https://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.html


https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.T.html

Line 167:


_, A = eigsh(csr_matrix(S, dtype=dtype, shape=(n, n)), rank)

The left side (_,A) seems to be in the form: eigenvalues, eigenvectors .
What is this??

Looking at:

Schneider, Hans;  Barker, George P. "Matrices and Linear Alegbra"




gives:

pg. 240
==========================================
(a) Let A be an nxn matrix. Then the scalar lambda is an eigenvalue of A if and only if (A - lamba*I) is singular.

(b) Let x be a nonzero column vector in C{sub:n,1} (insert: complex vector of n rows and 1 column). Then x is called an eigenvector belonging to (or associated with) the eigenvalue
lamba if an only if (A - lambda*I)*x = 0.
By Corollary (2.7.3) there is a non-zero vector x such that (A - Ilambda*I)x = 0 if and only if A - lambda*I is singular
===========================================
pg. 25
===========================================
(1.4.3) Definition: The square matrix A is termed nonsingular if and only if A posesses an inverse. If A has no inverse , A is called singular.
===========================================
pg. 240 (cont)
Hence lambda is an eigenvalue if and only if for some nonzero x, Ax = lamba*x . Observe that for an eigenvector x of A, Ax is a scalar multiple of x. Thus amd eigenvector of A is a vector whose direction is not changed when multiplied by A, although its magnitude may change. (when lambda is complex, this requires a careful defintion of direction).


https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.eigsh.html

https://docs.scipy.org/doc/scipy/reference/tutorial/arpack.html


https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.html

https://docs.python.org/2/tutorial/datastructures.html

https://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.html


[1] https://github.com/mnick/rescal.py/blob/master/rescal/rescal.py

line 173

Z = _updateZ(A, P, lmbdaV)
R = _updateR(X, A, lmbdaR)

https://shahriar.svbtle.com/underscores-in-python









Thursday, April 26, 2018

Practical Common List Bookmark

New post:

http://www.gigamonkeys.com/book/

stopped at:

http://www.gigamonkeys.com/book/practical-a-simple-database.html


======

a somewhat related question. How does a schema relate to a macro?? This came up. http://globin.cse.psu.edu/globin/html/docs/schema.doc.html

Tuesday, April 17, 2018

Notes from M Nickel's ISWC2011 Tutorial


Notes from following Maximilian Nickel's ISWC 2011 Tutorial (http://www.mit.edu/~mnick/) at
[http://www.cip.ifi.lmu.de/~nickel/iswc2012-slides/] .


Following slide 25: http://www.cip.ifi.lmu.de/~nickel/iswc2012-slides/#/25
The Web as a graph: Measurements, models and methods
https://link.springer.com/chapter/10.1007%2F3-540-48686-0_1

The Web as a graph: Measurements, models and methods
Review -by Shilpa Arora

http://www.cs.cmu.edu/~wcohen/10-802/fixed/Kleinberg_et_al%2C_ICCC_1999.html
Authoritative Sources in a Hyperlinked Environment
https://www.cs.cornell.edu/home/kleinber/auth.pdf


Following slide 26 (http://www.cip.ifi.lmu.de/~nickel/iswc2012-slides/#/26):
Singular Value Decomposition (SVD) tutorial
http://web.mit.edu/be.400/www/SVD/Singular_Value_Decomposition.htm


TripleRank: Ranking Semantic Web Data
By Tensor Decomposition
https://userpages.uni-koblenz.de/~staab/Research/Publications/2009/ISWC-triplerank-revised-version.pdf

TripleRank DataSets:

http://west.uni-koblenz.de/de/forschung/datensaetze/triplerank-data-sets


Other links:::
----------------------------------

Let's Play Gephi
http://matthieu-totet.fr/Koumin/2015/09/06/lets-play-gephi-dbpedia-rdf-sparql-and-your-favorite-actors/

There are lots of visualizations in this presentation that might be useful for understanding the visualizations in the 2011 presentation
https://cds.cern.ch/record/2306315

Watching this video (around 17:17) leads to this repository, which may be helpful::
https://github.com/mnick/holographic-embeddings
which references::
http://sameersingh.org/files/papers/logicmf-krr15.pdf
(
On Approximate Reasoning Capabilities of Low-Rank Vector Spaces)
which references
https://github.com/mledoze/countries


Thursday, April 12, 2018

I gave a talk at the OKC JUG

I gave a talk at the OKC JUG:

“Gremlin : Using Graph Thinking to Make Database Queries
Functional” (https://www.twitch.tv/videos/248817502)

I made a first hack at answering the questions. I had the following questions:
  • How is gremlin different from an object relational mapper?

Introduction to Object-Relational Mapping
LaunchCode
Published on Apr 3, 2017

https://www.youtube.com/watch?v=dHQ-I7kr_SY


-----------------------------------------------------------
  • How is TinkerPop different from Gremlin? What are the parts of TinkerPop?

All the Things:
=====================

BluePrints : Gremlin Structure API
Pipes : GraphTraversal
Frames : Traversal    (I think this is Gremlin)

Furnace : Graph Computer

Rexster : Gremlin server

-------------------------------------------------------------
  • Does TinkerPop necessarily work with a graph database??

With Sqlg (http://www.sqlg.org/) PostgresSql can be used, but is there a graph in memory that is produced somewhere??

------------------------------------------------------------

  • How can I do recursive queries with Gremlin??
See this video for a start.
https://www.youtube.com/watch?v=tLR-I53Gl9g&t=775s

Edit:: Here is a link to the talk: https://www.twitch.tv/videos/248817502

Gremlin - Using Graph Database Thinking to Make Database Queries Functional | OKC JUG

Tuesday, April 10, 2018

Tensor Factorization of large scale linked datasets

http://www.cip.ifi.lmu.de/~nickel/iswc2012-slides/

Results from running: Ext-Rescal
https://github.com/nzhiltsov/Ext-RESCAL

For inspiration see:
http://videolectures.net/lsoldm2013_nickel_tensor_factorization/


A Three-Way Model for Collective Learning on Multi-Relational Data

http://www.icml-2011.org/papers/438_icmlpaper.pdf
http://www.cip.ifi.lmu.de/~nickel/data/slides-icml2011.pdf

Logistic Tensor Factorization for Multi-Relational Datahttps://arxiv.org/pdf/1306.2084.pdf
Factorizing YAGO Scalable Machine Learning for Linked Data
http://www.dbs.ifi.lmu.de/%7Etresp/papers/p271.pdf


Machine Learning on Linked Data:
Tensors and Their Applications in Graph Structured Domains
http://www.cip.ifi.lmu.de/~nickel/iswc2012-slides/


cat rescal.log


DEBUG:RESCAL:[Config] rank: 2 | maxIter: 50 | conv: 1.0e-05 | lmbda: 0.0e+00
DEBUG:RESCAL:[Algorithm] The tensor norm: 3.00000
DEBUG:RESCAL:[Algorithm] The eigenvector based initialization will be performed.
DEBUG:RESCAL:Initializing tensor slices by summation required secs: 0.00045
DEBUG:RESCAL:eigenvector decomposition required secs: 0.00073
DEBUG:RESCAL:[Algorithm] Finished initialization.
DEBUG:RESCAL:[Algorithm] Preheating is going on.
DEBUG:RESCAL:[  0] total fit: 0.0000000000 | delta: 0.0000000000 | secs: 0.00090
DEBUG:RESCAL:[  1] total fit: 0.1717171717 | delta: 0.1717171717 | secs: 0.00095
DEBUG:RESCAL:[  2] total fit: 0.1679586563 | delta: 0.0037585154 | secs: 0.00067
DEBUG:RESCAL:[  3] total fit: 0.1669915530 | delta: 0.0009671034 | secs: 0.00076
DEBUG:RESCAL:[  4] total fit: 0.1667480072 | delta: 0.0002435458 | secs: 0.00081
DEBUG:RESCAL:[  5] total fit: 0.1666870092 | delta: 0.0000609979 | secs: 0.00077
DEBUG:RESCAL:[  6] total fit: 0.1666717528 | delta: 0.0000152565 | secs: 0.00075
DEBUG:RESCAL:[  7] total fit: 0.1666679382 | delta: 0.0000038146 | secs: 0.00067

cat extrescal.log

DEBUG:EXT-RESCAL:[Config] rank: 2 | maxIter: 50 | conv: 1.0e-05 | lmbda: 1.0e-03
DEBUG:EXT-RESCAL:[Algorithm] The tensor norm: 6.00000
DEBUG:EXT-RESCAL:[Algorithm] The extended matrix norm: 6.00000
DEBUG:EXT-RESCAL:[Algorithm] The eigenvector based initialization will be performed.
DEBUG:EXT-RESCAL:Initializing tensor slices by summation required secs: 0.00823
DEBUG:EXT-RESCAL:eigenvector decomposition required secs: 0.00459
DEBUG:EXT-RESCAL:[Algorithm] Finished initialization.
DEBUG:EXT-RESCAL:[Algorithm] Preheating is going on.
DEBUG:EXT-RESCAL:[  0] total fit: 0.0000000000 | tensor fit: 0.0000000000 | matrix fit: 0.0000000000 | delta: 0.0000000000 | secs: 0.00558
DEBUG:EXT-RESCAL:[  1] total fit: 0.4747103411 | tensor fit: 3.3519407763 | matrix fit: 2.3283205125 | delta: 0.4747103411 | secs: 0.00630
DEBUG:EXT-RESCAL:[  2] total fit: 0.4712640986 | tensor fit: 3.3643886333 | matrix fit: 2.2744289865 | delta: 0.0034462424 | secs: 0.00621
DEBUG:EXT-RESCAL:[  3] total fit: 0.4703993646 | tensor fit: 3.3703803959 | matrix fit: 2.2580441655 | delta: 0.0008647340 | secs: 0.01467
DEBUG:EXT-RESCAL:[  4] total fit: 0.4701842063 | tensor fit: 3.3730443071 | matrix fit: 2.2528058256 | delta: 0.0002151584 | secs: 0.00705
DEBUG:EXT-RESCAL:[  5] total fit: 0.4701298575 | tensor fit: 3.3741804443 | matrix fit: 2.2510327404 | delta: 0.0000543488 | secs: 0.00657
DEBUG:EXT-RESCAL:[  6] total fit: 0.4701152048 | tensor fit: 3.3746532816 | matrix fit: 2.2504019270 | delta: 0.0000146527 | secs: 0.00668
DEBUG:EXT-RESCAL:[  7] total fit: 0.4701103686 | tensor fit: 3.3748470868 | matrix fit: 2.2501688141 | delta: 0.0000048362 | secs: 0.00661

cat entity.embeddings.csv 

5.287400282344740798e-01 -2.648288074937905172e-17
6.472985753526332431e-01 -1.883524571199644730e-17
6.472985753526332431e-01 -1.883524571199644730e-17
2.528510059971223606e-03 -8.399779633628449750e-20
9.723663381107547794e-17 7.118437655042088030e-01
9.723718319815804104e-17 7.118437655042088030e-01

cat term.embeddings.csv 

4.730825851270915039e-01 -6.977337002813972351e-17
1.157697052140589156e+00 -1.451761439325526721e-16
4.522254109924176389e-03 -5.860147020766050828e-19
4.822701779013331954e-17 1.404572401961088790e+00

cat latent.factors.csv 

5.476271649231128080e-01 -1.168831819383593920e-16
-6.070133651429397840e-17 1.295001708078205427e-32
1.069584306490454703e-03 -1.659206118320981211e-19
-2.282874647233581876e-19 3.540155448418387818e-35
1.741390346565283288e-33 5.092367925378079864e-17
5.092333426231983632e-17 1.478663144852583988e+00

Tuesday, April 3, 2018

postgresql weith java experiments

 Day 1 Attempt:::

psql
psql: FATAL:  role "brent" does not exist

sudo -u postgres -i
createuser brent

CREATE DATABASE test

https://stackoverflow.com/questions/15301826/psql-fatal-role-postgres-does-not-exist


https://stackoverflow.com/questions/11919391/postgresql-error-fatal-role-username-does-not-exist#11919677


Next step, play with postgresql with Java:

http://zetcode.com/java/postgresql/

==========================================
Day 2 Attempt::

psql
CREATE USER brent WITH PASSWORD 'brent';
CREATE ROLE
CREATE DATABASE testing WITH OWNER = brent;
CREATE DATABASE
GRANT ALL PRIVILEGES ON DATABASE testing to brent;
GRANT
\connect testing


create a table::
https://www.tutorialspoint.com/postgresql/postgresql_create_table.htm
https://www.postgresql.org/docs/9.1/static/sql-createtable.html


CREATE TABLE superhero (ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, POWER TEXT NOT NULL);
CREATE TABLE


\dt
           List of relations
 Schema |   Name    | Type  |  Owner  
--------+-----------+-------+----------
 public | superhero | table | postgres
(1 row)
http://zetcode.com/java/postgresql/

==================


sudo -u postgres createuser --interactive --password batman

sudo -u postgres createdb testdb -O batman


sudo vi /etc/postgresql/9.5/main/pg_hba.conf

sudo service postgresql restart

psql -U batman -d testdb -W

=============================

Day 3 Attempt::


$ su - postgres
$ psql template1
template1=# CREATE USER tester WITH PASSWORD 'test_password';
template1=# GRANT ALL PRIVILEGES ON DATABASE "test_database" to tester;
template1=# \q


sudo -u postgres createdb sqlgraphdb -O batman


sudo -u postgres createdb sqlgraphdb -O batman

psql -U batman -d sqlgraphdb -W

===============================

Day 4 Attempt::

\c testdb
\dt