0

I would do a subtraction between two dense vectors, both of them are the result of a dataset and a function. there is an example

1. The first dense vector is a row of dataset(*, 2)

BroadcastedRows(DenseVector(0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0))

2. The second dense vector is a return of predict_coef_sgd(dataset, coef)

DenseVector(0.2987569855650975,  0.14595105593031163, 0.08533326519733725,
            0.21973731424800344, 0.24705900008926596, 0.9547021347460022, 
            0.8620341905282771,  0.9717729050420985,  0.9992954520878627, 
            0.9054893228110497)

I got an error when I subtract them

dataset(*, 2) - predict_coef_sgd(dataset, coef)

Name: Compile Error
Message: <console>:36: error: could not find implicit value for parameter op: breeze.linalg.operators.OpSub.Impl2[breeze.linalg.BroadcastedRows[breeze.linalg.DenseVector[Double],breeze.linalg.DenseVector[Double]],breeze.linalg.DenseVector[Double],That]
       dataset(*, 2) - predict_coef_sgd(dataset, coef)
                     ^
StackTrace: 

Please comment how to convert "BroadcastedRows(DenseVector" to a dense vector. Thank you.

madeinQuant
  • 1,721
  • 1
  • 18
  • 29
  • Related, maybe helpful https://stackoverflow.com/questions/32745724/row-broadcasting-and-transposed-vectors – John Mar 08 '18 at 18:12
  • Thank you, john, I did but I don't understand why. Anyway thank for your help – madeinQuant Mar 09 '18 at 03:11
  • Honestly, Breeze is a great library, but it is not documented well, so I have a hard time recommending it. It's very confusing to do things like this. – John Mar 09 '18 at 15:20

1 Answers1

0

According to John's comment, referring row-broadcasting and transposed vectors? it solved, however, I don't understand why, please feel free to comment if you would explain that in details

(dataset.t(2,::) - predict_coef_sgd(dataset, coef).t).t

DenseVector(-0.2987569855650975, -0.14595105593031163, -0.08533326519733725,
            -0.21973731424800344, -0.24705900008926596, 0.045297865253997815,
             0.13796580947172288, 0.028227094957901544, 7.045479121372544E-4, 
             0.09451067718895034)
madeinQuant
  • 1,721
  • 1
  • 18
  • 29