Created
July 11, 2017 20:49
-
-
Save romeokienzler/760f4a3879ea9d9f73cff1980e1235af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"\n", | |
"class Neural_Network(object):\n", | |
" def __init__(self): \n", | |
" #Define Hyperparameters\n", | |
" self.inputLayerSize = 2\n", | |
" self.outputLayerSize = 1\n", | |
" self.hiddenLayerSize = 3\n", | |
" \n", | |
" #Weights (parameters)\n", | |
" self.W1 = np.random.randn(self.inputLayerSize, self.hiddenLayerSize)\n", | |
" self.W2 = np.random.randn(self.hiddenLayerSize, self.outputLayerSize)\n", | |
" \n", | |
" def forward(self, X):\n", | |
" #Propagate inputs though network\n", | |
" self.z2 = np.dot(X, self.W1)\n", | |
" self.a2 = self.sigmoid(self.z2)\n", | |
" self.z3 = np.dot(self.a2, self.W2)\n", | |
" yHat = self.sigmoid(self.z3) \n", | |
" return yHat\n", | |
" \n", | |
" def sigmoid(self, z):\n", | |
" #Apply sigmoid activation function to scalar, vector, or matrix\n", | |
" return 1/(1+np.exp(-z))\n", | |
" \n", | |
" def costFunction(self, X, y):\n", | |
" #Compute cost for given X,y, use weights already stored in class.\n", | |
" self.yHat = self.forward(X)\n", | |
" #print y\n", | |
" #print self.yHat\n", | |
" J = 0.5*sum((y-self.yHat)**2)\n", | |
" return J\n", | |
" \n", | |
" def sigmoidPrime(self,z):\n", | |
" #Gradient of sigmoid\n", | |
" return np.exp(-z)/((1+np.exp(-z))**2)\n", | |
" \n", | |
" def tanh(self,x):\n", | |
" return np.tanh(x)\n", | |
"\n", | |
" def tanh_deriv(self,x):\n", | |
" return 1.0 - np.tanh(x)**2\n", | |
"\n", | |
" def logistic(x):\n", | |
" return 1/(1 + np.exp(-x))\n", | |
"\n", | |
" def logistic_derivative(x):\n", | |
" return logistic(x)*(1-logistic(x))\n", | |
"\n", | |
" def costFunctionPrime(self, X, y):\n", | |
" #Compute derivative with respect to W and W2 for a given X and y:\n", | |
" self.yHat = self.forward(X)\n", | |
" \n", | |
" delta3 = np.multiply(-(y-self.yHat), self.sigmoidPrime(self.z3))\n", | |
" #delta3 = np.multiply(-(y-self.yHat), self.z3)\n", | |
" dJdW2 = np.dot(self.a2.T, delta3)\n", | |
" \n", | |
" delta2 = np.dot(delta3, self.W2.T)*self.sigmoidPrime(self.z2)\n", | |
" dJdW1 = np.dot(X.T, delta2) \n", | |
" \n", | |
" return dJdW1, dJdW2" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X = np.array(([3,5], [5,1], [10,2]), dtype=float)\n", | |
"y = np.array(([75], [82], [93]), dtype=float)\n", | |
"print X.shape\n", | |
"print y.shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X = np.random.rand(10000,2)\n", | |
"y = np.apply_along_axis( lambda element: element[0]+element[1], axis=1, arr=X )\n", | |
"y.shape=(10000,1)\n", | |
"print X.shape\n", | |
"print y.shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"NN = Neural_Network()\n", | |
"max_iterations = 100\n", | |
"iter = 0\n", | |
"learningRate = 0.00001\n", | |
"while iter < max_iterations:\n", | |
" dJdW1, dJdW2 = NN.costFunctionPrime(X,NN.sigmoid(y))\n", | |
"\n", | |
" \n", | |
" #update\n", | |
" upd_W1 = NN.W1 - learningRate * dJdW1\n", | |
" upd_W2 = NN.W2 - learningRate * dJdW2\n", | |
" NN.W1 = NN.W1 + upd_W1\n", | |
" NN.W2 = NN.W2 + upd_W2\n", | |
" \n", | |
" print NN.costFunction(X,NN.sigmoid(y))\n", | |
" \n", | |
" iter = iter + 1\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"print NN.tanh(y)\n", | |
"print NN.forward(X)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Archiver-Version: Plexus Archiver\n", | |
"Artifact-Id: systemml\n", | |
"Build-Jdk: 1.8.0_131\n", | |
"Build-Time: 2017-07-06 16:46:00 UTC\n", | |
"Built-By: reinwald\n", | |
"Created-By: Apache Maven 3.3.9\n", | |
"Group-Id: org.apache.systemml\n", | |
"Main-Class: org.apache.sysml.api.DMLScript\n", | |
"Manifest-Version: 1.0\n", | |
"Minimum-Recommended-Spark-Version: 2.1.0\n", | |
"Version: 1.0.0-SNAPSHOT\n", | |
"\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"u'2.1.0'" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from systemml import MLContext, dml\n", | |
"ml = MLContext(sc)\n", | |
"print(ml.info())\n", | |
"sc.version" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"sigmoid = function(z) {\n", | |
" z=1/(1+exp(-z))\n", | |
"}\n", | |
"\n", | |
"X=matrix(c(3,5,5,1,10,2), nrow=3, ncol=2) \n", | |
"inputLayerSize = 2\n", | |
"outputLayerSize = 1\n", | |
"hiddenLayerSize = 3\n", | |
"\n", | |
"W1 = replicate(hiddenLayerSize, rnorm(inputLayerSize)) \n", | |
"W2 = replicate(outputLayerSize, rnorm(hiddenLayerSize)) \n", | |
"\n", | |
"feedForward = function (X,\n", | |
" W1,\n", | |
" W2) {\n", | |
" a2 = sigmoid(X %*% W1) \n", | |
" Y = sigmoid(a2 %*% W2)\n", | |
"}\n", | |
"\n", | |
"Yhat=feedForward(X,W1,W2)\n", | |
"print(nrow(X))\n", | |
"print(ncol(X))\n", | |
"print(nrow(W1))\n", | |
"print(ncol(W1))\n", | |
"print(Yhat)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"replicate(2, rnorm(20)) " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"script = \"\"\"\n", | |
"\n", | |
"#\n", | |
"sigmoid = function(matrix[double] z) return (matrix[double] z) {\n", | |
" z = 1/(1+exp(-z))\n", | |
"}\n", | |
"\n", | |
"\n", | |
"sigmoidPrime = function(matrix[double] z) return (matrix[double] z) {\n", | |
" #Gradient of sigmoid\n", | |
" z = exp(-z)/(1+exp(-z))\n", | |
"}\n", | |
"\n", | |
"inputLayerSize = 2\n", | |
"outputLayerSize = 1\n", | |
"hiddenLayerSize = 3\n", | |
"\n", | |
"W1 = rand(rows=inputLayerSize,cols=hiddenLayerSize)\n", | |
"W2 = rand(rows=hiddenLayerSize,cols=outputLayerSize)\n", | |
"\n", | |
"feedForward = function (matrix[double] X,\n", | |
" matrix[double] W1,\n", | |
" matrix[double] W2) return (matrix[double] z2,matrix[double] a2,matrix[double] z3,matrix[double] Y) {\n", | |
" z2 = X %*% W1\n", | |
" a2 = sigmoid(z2)\n", | |
" z3 = (a2 %*% W2)\n", | |
" Y = sigmoid(z3)\n", | |
"}\n", | |
"\n", | |
"\n", | |
"gradient = function(matrix[double] X,\n", | |
" matrix[double] W1,\n", | |
" matrix[double] W2,\n", | |
" matrix[double] Y) return (matrix[double] dJdW1,matrix[double] dJdW1) {\n", | |
" #Compute derivative with respect to W and W2 for a given X and y:\n", | |
" [z2,a2,z3,Yhat] = feedForward(X,W1,W2)\n", | |
" \n", | |
" smpz3 = sigmoidPrime(z3)\n", | |
" delta3 = -(Y-Yhat) * smpz3\n", | |
" dJdW2 = t(a2) %*% delta3\n", | |
" \n", | |
" smpz2 = sigmoidPrime(z2)\n", | |
" delta2 = (delta3 %*% t(W2))*smpz2\n", | |
" dJdW1 = t(X) %*% delta2 \n", | |
"}\n", | |
"\n", | |
"max_iterations = 100\n", | |
"iter = 0\n", | |
"learningRate = 0.00001\n", | |
"while( iter < max_iterations ){\n", | |
" smy = sigmoid(y)\n", | |
" [dJdW1, dJdW2] = gradient(X,W1,W2,smy)\n", | |
"\n", | |
" \n", | |
" #update\n", | |
" W1 = W1 - learningRate * dJdW1\n", | |
" W2 = W2 - learningRate * dJdW2\n", | |
" \n", | |
" iter = iter + 1\n", | |
"}\n", | |
"\"\"\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "Py4JJavaError", | |
"evalue": "An error occurred while calling o79.execute.\n: org.apache.sysml.api.mlcontext.MLContextException: Exception when executing script\n\tat org.apache.sysml.api.mlcontext.MLContext.execute(MLContext.java:320)\n\tat org.apache.sysml.api.mlcontext.MLContext.execute(MLContext.java:293)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)\n\tat java.lang.reflect.Method.invoke(Method.java:507)\n\tat py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)\n\tat py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)\n\tat py4j.Gateway.invoke(Gateway.java:280)\n\tat py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)\n\tat py4j.commands.CallCommand.execute(CallCommand.java:79)\n\tat py4j.GatewayConnection.run(GatewayConnection.java:214)\n\tat java.lang.Thread.run(Thread.java:785)\nCaused by: org.apache.sysml.api.mlcontext.MLContextException: Exception occurred while executing runtime program\n\tat org.apache.sysml.api.mlcontext.ScriptExecutor.executeRuntimeProgram(ScriptExecutor.java:397)\n\tat org.apache.sysml.api.mlcontext.ScriptExecutor.execute(ScriptExecutor.java:311)\n\tat org.apache.sysml.api.mlcontext.MLContext.execute(MLContext.java:316)\n\t... 12 more\nCaused by: org.apache.sysml.runtime.DMLRuntimeException: org.apache.sysml.runtime.DMLRuntimeException: ERROR: Runtime error in while program block generated from while statement block between lines 52 and 62 -- Error evaluating while program block\n\tat org.apache.sysml.runtime.controlprogram.Program.execute(Program.java:130)\n\tat org.apache.sysml.api.ScriptExecutorUtils.executeRuntimeProgram(ScriptExecutorUtils.java:95)\n\tat org.apache.sysml.api.ScriptExecutorUtils.executeRuntimeProgram(ScriptExecutorUtils.java:54)\n\tat org.apache.sysml.api.mlcontext.ScriptExecutor.executeRuntimeProgram(ScriptExecutor.java:395)\n\t... 14 more\nCaused by: org.apache.sysml.runtime.DMLRuntimeException: ERROR: Runtime error in while program block generated from while statement block between lines 52 and 62 -- Error evaluating while program block\n\tat org.apache.sysml.runtime.controlprogram.WhileProgramBlock.execute(WhileProgramBlock.java:177)\n\tat org.apache.sysml.runtime.controlprogram.Program.execute(Program.java:123)\n\t... 17 more\nCaused by: org.apache.sysml.runtime.DMLRuntimeException: ERROR: Runtime error in program block generated from statement block between lines 58 and 61 -- Error evaluating instruction: CP°-*°W2·MATRIX·DOUBLE°1.0E-5·SCALAR·DOUBLE·true°dJdW2·MATRIX·DOUBLE°_mVar117·MATRIX·DOUBLE\n\tat org.apache.sysml.runtime.controlprogram.ProgramBlock.executeSingleInstruction(ProgramBlock.java:320)\n\tat org.apache.sysml.runtime.controlprogram.ProgramBlock.executeInstructions(ProgramBlock.java:221)\n\tat org.apache.sysml.runtime.controlprogram.ProgramBlock.execute(ProgramBlock.java:167)\n\tat org.apache.sysml.runtime.controlprogram.WhileProgramBlock.execute(WhileProgramBlock.java:165)\n\t... 18 more\nCaused by: java.lang.RuntimeException: Block sizes are not matched for binary cell operations: 3x1 vs 2x3\n\tat org.apache.sysml.runtime.matrix.data.MatrixBlock.binaryOperations(MatrixBlock.java:2872)\n\tat org.apache.sysml.runtime.instructions.cp.PlusMultCPInstruction.processInstruction(PlusMultCPInstruction.java:66)\n\tat org.apache.sysml.runtime.controlprogram.ProgramBlock.executeSingleInstruction(ProgramBlock.java:290)\n\t... 21 more\n", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m\u001b[0m", | |
"\u001b[0;31mPy4JJavaError\u001b[0mTraceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-15-0641ddf39557>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprog\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdml\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mscript\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mml\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprog\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;31m#print result.get(\"Yhat\").toNumPy()\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/gpfs/fs01/user/s4c2-1e12ab68a45670-980ba6aaa6c3/.local/lib/python2.7/site-packages/systemml/mlcontext.pyc\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(self, script)\u001b[0m\n\u001b[1;32m 338\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mval\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mscript\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_output\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 339\u001b[0m \u001b[0mscript_java\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mout\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mval\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 340\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mMLResults\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_ml\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mscript_java\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_sc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 341\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 342\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0msetStatistics\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstatistics\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/usr/local/src/spark21master/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args)\u001b[0m\n\u001b[1;32m 1131\u001b[0m \u001b[0manswer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgateway_client\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msend_command\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcommand\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1132\u001b[0m return_value = get_return_value(\n\u001b[0;32m-> 1133\u001b[0;31m answer, self.gateway_client, self.target_id, self.name)\n\u001b[0m\u001b[1;32m 1134\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1135\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mtemp_arg\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mtemp_args\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/usr/local/src/spark21master/spark/python/pyspark/sql/utils.py\u001b[0m in \u001b[0;36mdeco\u001b[0;34m(*a, **kw)\u001b[0m\n\u001b[1;32m 61\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mdeco\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 63\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 64\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mpy4j\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprotocol\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPy4JJavaError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 65\u001b[0m \u001b[0ms\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjava_exception\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtoString\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/usr/local/src/spark21master/spark/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py\u001b[0m in \u001b[0;36mget_return_value\u001b[0;34m(answer, gateway_client, target_id, name)\u001b[0m\n\u001b[1;32m 317\u001b[0m raise Py4JJavaError(\n\u001b[1;32m 318\u001b[0m \u001b[0;34m\"An error occurred while calling {0}{1}{2}.\\n\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 319\u001b[0;31m format(target_id, \".\", name), value)\n\u001b[0m\u001b[1;32m 320\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 321\u001b[0m raise Py4JError(\n", | |
"\u001b[0;31m<type 'str'>\u001b[0m: (<type 'exceptions.UnicodeEncodeError'>, UnicodeEncodeError('ascii', u'An error occurred while calling o79.execute.\\n: org.apache.sysml.api.mlcontext.MLContextException: Exception when executing script\\n\\tat org.apache.sysml.api.mlcontext.MLContext.execute(MLContext.java:320)\\n\\tat org.apache.sysml.api.mlcontext.MLContext.execute(MLContext.java:293)\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)\\n\\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)\\n\\tat java.lang.reflect.Method.invoke(Method.java:507)\\n\\tat py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)\\n\\tat py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)\\n\\tat py4j.Gateway.invoke(Gateway.java:280)\\n\\tat py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)\\n\\tat py4j.commands.CallCommand.execute(CallCommand.java:79)\\n\\tat py4j.GatewayConnection.run(GatewayConnection.java:214)\\n\\tat java.lang.Thread.run(Thread.java:785)\\nCaused by: org.apache.sysml.api.mlcontext.MLContextException: Exception occurred while executing runtime program\\n\\tat org.apache.sysml.api.mlcontext.ScriptExecutor.executeRuntimeProgram(ScriptExecutor.java:397)\\n\\tat org.apache.sysml.api.mlcontext.ScriptExecutor.execute(ScriptExecutor.java:311)\\n\\tat org.apache.sysml.api.mlcontext.MLContext.execute(MLContext.java:316)\\n\\t... 12 more\\nCaused by: org.apache.sysml.runtime.DMLRuntimeException: org.apache.sysml.runtime.DMLRuntimeException: ERROR: Runtime error in while program block generated from while statement block between lines 52 and 62 -- Error evaluating while program block\\n\\tat org.apache.sysml.runtime.controlprogram.Program.execute(Program.java:130)\\n\\tat org.apache.sysml.api.ScriptExecutorUtils.executeRuntimeProgram(ScriptExecutorUtils.java:95)\\n\\tat org.apache.sysml.api.ScriptExecutorUtils.executeRuntimeProgram(ScriptExecutorUtils.java:54)\\n\\tat org.apache.sysml.api.mlcontext.ScriptExecutor.executeRuntimeProgram(ScriptExecutor.java:395)\\n\\t... 14 more\\nCaused by: org.apache.sysml.runtime.DMLRuntimeException: ERROR: Runtime error in while program block generated from while statement block between lines 52 and 62 -- Error evaluating while program block\\n\\tat org.apache.sysml.runtime.controlprogram.WhileProgramBlock.execute(WhileProgramBlock.java:177)\\n\\tat org.apache.sysml.runtime.controlprogram.Program.execute(Program.java:123)\\n\\t... 17 more\\nCaused by: org.apache.sysml.runtime.DMLRuntimeException: ERROR: Runtime error in program block generated from statement block between lines 58 and 61 -- Error evaluating instruction: CP\\xb0-*\\xb0W2\\xb7MATRIX\\xb7DOUBLE\\xb01.0E-5\\xb7SCALAR\\xb7DOUBLE\\xb7true\\xb0dJdW2\\xb7MATRIX\\xb7DOUBLE\\xb0_mVar117\\xb7MATRIX\\xb7DOUBLE\\n\\tat org.apache.sysml.runtime.controlprogram.ProgramBlock.executeSingleInstruction(ProgramBlock.java:320)\\n\\tat org.apache.sysml.runtime.controlprogram.ProgramBlock.executeInstructions(ProgramBlock.java:221)\\n\\tat org.apache.sysml.runtime.controlprogram.ProgramBlock.execute(ProgramBlock.java:167)\\n\\tat org.apache.sysml.runtime.controlprogram.WhileProgramBlock.execute(WhileProgramBlock.java:165)\\n\\t... 18 more\\nCaused by: java.lang.RuntimeException: Block sizes are not matched for binary cell operations: 3x1 vs 2x3\\n\\tat org.apache.sysml.runtime.matrix.data.MatrixBlock.binaryOperations(MatrixBlock.java:2872)\\n\\tat org.apache.sysml.runtime.instructions.cp.PlusMultCPInstruction.processInstruction(PlusMultCPInstruction.java:66)\\n\\tat org.apache.sysml.runtime.controlprogram.ProgramBlock.executeSingleInstruction(ProgramBlock.java:290)\\n\\t... 21 more\\n', 2559, 2560, 'ordinal not in range(128)'))" | |
] | |
} | |
], | |
"source": [ | |
"import numpy as np\n", | |
"X = np.random.rand(10000,2)\n", | |
"y = np.apply_along_axis( lambda element: element[0]+element[1], axis=1, arr=X )\n", | |
"y.shape=(10000,1)\n", | |
"prog = dml(script).input(X=X).input(y=y)\n", | |
"\n", | |
"result = ml.execute(prog)\n", | |
"\n", | |
"#print result.get(\"Yhat\").toNumPy()\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2 with Spark 2.1", | |
"language": "python", | |
"name": "python2-spark21" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.11" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment