1

Breeze Linear Algebra パッケージ ( https://github.com/scalanlp/breeze ) と GF2 フィールドを表す独自のデータ型を使用して、ハミング コーディングを実装しようとしています。これまでのところ、GF2 を正常に実装できました。

package humming

trait GF2 {
  def + (that: GF2): GF2
  def * (that: GF2): GF2

  def / (that: GF2) = that match {
    case Zero => throw new IllegalArgumentException("Div by 0")
    case _ => this
  }
}

object Zero extends GF2 {
  override def toString = "Zero"
  def + (that: GF2) = that
  def * (that: GF2) = this
}

object One extends GF2 {
  override def toString = "One"
  def + (that: GF2) = that match { case One => Zero ; case _ => this }
  def * (that: GF2) = that match { case One => this ; case _ => that }
}

GF2 値のマトリックスを作成するために必要な型クラス:

import breeze.linalg._
import breeze.numerics._
import breeze.storage._
import scala.reflect._
import breeze.math._
import humming._

implicit object GF2DefaultArrayValue extends DefaultArrayValue[GF2] {
  override def value = Zero
}

implicit object GF2Semiring extends Semiring[GF2] {
  def defaultArrayValue = GF2DefaultArrayValue
  def manifest = classTag[GF2]
  def zero = Zero
  def one = One

  def ==(a: GF2, b: GF2) = a == b
  def !=(a: GF2, b: GF2) = a != b
  def +(a: GF2, b: GF2) = a + b
  def *(a: GF2, b: GF2) = a * b
}

val a = DenseMatrix.eye[GF2](5)

しかし、マトリックスをそれ自体に追加しようとすると、次のエラーが発生します。

a + a  
// could not find implicit value for parameter op:  
// breeze.linalg.operators.BinaryOp[breeze.linalg.DenseMatrix[humming.GF2],  
// breeze.linalg.DenseMatrix[humming.GF2],breeze.linalg.operators.OpAdd,That]

この時点で、どの型クラスを実装する必要があるのか​​ よくわからないため、行き詰まっています。見てbreeze.linalg.operatorsもあまり役に立ちませんでした。問題は、GF2 を Breeze と組み合わせて、すべての行列/ベクトル操作をサポートできるようにするにはどうすればよいかということです。

==============
上記の問題はバージョン 0.6 で解決されて
いますが、行列にベクトルや値を掛けることはまだできません。

val a = DenseMatrix.eye[GF2](5)
val b = DenseVector.ones[GF2](5)
a + a // OK

a * b  
// Could not find an implicit implementation for this UFunc with arguments  
// breeze.linalg.DenseMatrix[humming.GF2], breeze.linalg.DenseVector[humming.GF2]

a + One  
// Could not find an implicit implementation for this UFunc with arguments  
// breeze.linalg.DenseMatrix[humming.GF2], humming.One.type

UFunc実装を提供する必要があると思います。それはどのように見えるべきですか?

4

1 に答える 1