Reputation: 57
When we have a data set with negative value, can we apply non negative matrix factorisation? If yes, how?
Upvotes: 0
Views: 2559
Reputation:
You can add min value of the dataframe to entire cell to make it non-negative
set.seed(1)
x <- rmatrix(5,5, rnorm, mean=0, sd=5)
x
[,1] [,2] [,3] [,4] [,5]
[1,] -3.1322691 -4.102342 7.558906 -0.22466805 4.5948869
[2,] 0.9182166 2.437145 1.949216 -0.08095132 3.9106815
[3,] -4.1781431 3.691624 -3.106203 4.71918105 0.3728249
[4,] 7.9764040 2.878907 -11.073499 4.10610598 -9.9467585
[5,] 1.6475389 -1.526942 5.624655 2.96950661 3.0991287
nneg(x, method='min')
[,1] [,2] [,3] [,4] [,5]
[1,] 7.941230 6.971158 18.632405 10.84883 15.668386
[2,] 11.991716 13.510645 13.022716 10.99255 14.984181
[3,] 6.895356 14.765123 7.967297 15.79268 11.446324
[4,] 19.049903 13.952406 0.000000 15.17961 1.126741
[5,] 12.721038 9.546558 16.698154 14.04301 14.172628
Upvotes: 1
Reputation: 171
If you are using R:
nneg.data.matrix <- nneg(data.matrix)
nneg.data.matrix < 0
The additional argument 'method' choices are:
pmax - Each entry is constrained to be above threshold threshold.
posneg - The matrix is split into its "positive" and "negative" parts, with the entries of each part constrained to be above threshold threshold. The result consists in these two parts stacked in rows (i.e. rbind-ed) into a single matrix, which has double the number of rows of the input matrix object.
absolute - The absolute value of each entry is constrained to be above threshold threshold.
min - Global shift by adding the minimum entry to each entry, only if it is negative, and then apply threshold.
Upvotes: 3