| #------------------------------------------------------------- |
| # |
| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| # |
| #------------------------------------------------------------- |
| |
| source("../../slabUtils.dml") as utils |
| |
| dataPath = $1 |
| X = read(dataPath, format="csv") |
| rvect = rand(rows=1, cols=1) |
| y = rvect > 0.80 |
| p = sum( X ) |
| q = sum( y ) |
| print(p) |
| print(q) |
| |
| |
| for(ix in 1:5){ |
| tmp = gnmf(X, 10, 10) |
| print(tmp) |
| } |
| |
| gnmf = function(matrix[double] X, Integer r, Integer iterations) |
| return (integer iteration) { |
| |
| W = rand(rows = nrow(X), cols = r, pdf = 'uniform') |
| H = rand(rows = r, cols = ncol(X), pdf = 'uniform') |
| |
| for (i in 1:3) { |
| W = W * ((X %*% t(H)) / (W %*% (H %*% t(H)))) |
| H = H * ((t(W) %*% X) / ((t(W) %*% W) %*% H)) |
| } |
| if ((as.scalar(W[1,1]) > 0) & (as.scalar(H[1,1]) > 0)) { |
| print(as.scalar(H[1,1])) |
| print(as.scalar(W[1,1])) |
| } |
| |
| iteration = 0 |
| } |