本文整理汇总了PHP中Matrix类的典型用法代码示例。如果您正苦于以下问题:PHP Matrix类的具体用法?PHP Matrix怎么用?PHP Matrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Matrix类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: compute
/**
* Return all possibility for the matrix
*
* @return array
*/
public function compute()
{
$dimensions = $this->dimensions;
if (empty($dimensions)) {
return array();
}
// Pop first dimension
$values = reset($dimensions);
$name = key($dimensions);
unset($dimensions[$name]);
// Create all possiblites for the first dimension
$posibilities = array();
foreach ($values as $v) {
$posibilities[] = array($name => $v);
}
// If only one dimension return simple all the possibilites created (break point of recursivity)
if (empty($dimensions)) {
return $posibilities;
}
// If not create a new matrix with remaining dimension
$matrix = new Matrix();
foreach ($dimensions as $name => $values) {
$matrix->setDimension($name, $values);
}
$result = $matrix->compute();
$newResult = array();
foreach ($result as $value) {
foreach ($posibilities as $possiblity) {
$newResult[] = $value + $possiblity;
}
}
return $newResult;
}
开发者ID:Chris7,项目名称:JoliCi,代码行数:38,代码来源:Matrix.php
示例2: getD
/**
* Get D - the diagonal matrix.
*
* @return matrix D
*/
public function getD()
{
$D = new Matrix($this->_matrix->rows(), $this->_matrix->columns());
for ($i = 0; $i < $D->rows(); $i++) {
$D->set($i, $i, $this->_matrix->get($i, $i));
}
return $D;
}
开发者ID:hoenirvili,项目名称:cn,代码行数:13,代码来源:Cholesky.php
示例3: testShouldReturnOne
public function testShouldReturnOne()
{
$matrix = new Matrix();
$matrix->setSize(5);
$matrix->setValues(array(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5));
$analyzer = new MatrixAnalyzer();
$analyzer->getGreaterProduct($matrix);
}
开发者ID:amaivsimau,项目名称:dojos,代码行数:8,代码来源:MatrixAnalyzerTest.php
示例4: testConstructor
/**
* @dataProvider dataProviderForConstructor
*/
public function testConstructor(array $M, array $V)
{
$R = new RowVector($M);
$V = new Matrix($V);
$this->assertInstanceOf('MathPHP\\LinearAlgebra\\RowVector', $R);
$this->assertInstanceOf('MathPHP\\LinearAlgebra\\Matrix', $R);
$this->assertEquals($V[0], $R[0]);
$this->assertEquals(1, $V->getM());
$this->assertEquals(count($M), $V->getN());
}
开发者ID:markrogoyski,项目名称:math-php,代码行数:13,代码来源:RowVectorTest.php
示例5: testMatrixGetReturnsCorrectValue
public function testMatrixGetReturnsCorrectValue()
{
$testArray = array(array(1, 2, 3), array(0, 2, 1), array(2.5, 1, 3));
$this->object = new RationalMatrix($testArray);
for ($r = 1; $r < 4; $r++) {
for ($c = 1; $c < 4; $c++) {
$this->assertEquals(RationalTypeFactory::create($testArray[$r - 1][$c - 1]), $this->object->get($r, $c));
}
}
}
开发者ID:chippyash,项目名称:math-matrix,代码行数:10,代码来源:RationalMatrixTest.php
示例6: testJackingAHumanIncreasesTheCount
public function testJackingAHumanIncreasesTheCount()
{
$human = $this->getMock('Human', null, array(), 'MockHuman', null, false);
$humanFactory = $this->getMock('HumanFactory');
$humanFactory->expects($this->once())->method('create')->will($this->returnValue($human));
$matrix = new Matrix();
$matrix->setHumanFactory($humanFactory);
$expectedCount = $matrix->count();
$matrix->jackIn('robin');
$this->assertEquals($expectedCount + 1, $matrix->count());
}
开发者ID:nottrobin,项目名称:tdd-training-exercises,代码行数:11,代码来源:MatrixTest.php
示例7: multiplicationScalar
public function multiplicationScalar($multiplier)
{
$result = new Matrix($this->matrix->getNumRows(), $this->matrix->getNumCols(), $this->precision);
for ($row = 1; $row <= $this->matrix->getNumRows(); $row++) {
for ($col = 1; $col <= $this->matrix->getNumCols(); $col++) {
$newValue = bcmul($this->matrix->getPoint($row, $col), $multiplier, $this->precision);
$result->setPoint($row, $col, $newValue);
}
}
return $result;
}
开发者ID:skilla,项目名称:matrix,代码行数:11,代码来源:Operations.php
示例8: _construct_view_matrix
private function _construct_view_matrix(Vertex $origin, Matrix $orientation)
{
$this->_origin = $origin;
$this->_tT = new Matrix(array('preset' => Matrix::TRANSLATION, 'vtc' => (new Vector(array('dest' => $origin)))->opposite()));
$this->_tR = $orientation->transpose();
print $this->_tT;
print $this->_tR;
$this->_view_matrix = $this->_tR->mult($this->_tT);
if (self::$verbose) {
echo "Camera instance constructed." . PHP_EOL;
}
}
开发者ID:eXcomm,项目名称:3D-PHP-Class,代码行数:12,代码来源:Camera.class.php
示例9: testConstructor
/**
* @dataProvider dataProviderForConstructor
*/
public function testConstructor(array $M, array $V)
{
$C = new ColumnVector($M);
$V = new Matrix($V);
$this->assertInstanceOf('MathPHP\\LinearAlgebra\\ColumnVector', $C);
$this->assertInstanceOf('MathPHP\\LinearAlgebra\\Matrix', $C);
foreach ($M as $row => $value) {
$this->assertEquals($value, $V[$row][0]);
}
$this->assertEquals(count($M), $V->getM());
$this->assertEquals(1, $V->getN());
}
开发者ID:markrogoyski,项目名称:math-php,代码行数:15,代码来源:ColumnVectorTest.php
示例10: testCompute
public function testCompute()
{
$matrix = new Matrix();
$matrix->setDimension('a', array(1, 2, 3));
$matrix->setDimension('b', array(1, 2, 3));
$matrix->setDimension('c', array(1, 2, 3));
$possibilities = $matrix->compute();
$expected = array(array('a' => 1, 'b' => 1, 'c' => 1), array('a' => 1, 'b' => 1, 'c' => 2), array('a' => 1, 'b' => 1, 'c' => 3), array('a' => 1, 'b' => 2, 'c' => 1), array('a' => 1, 'b' => 2, 'c' => 2), array('a' => 1, 'b' => 2, 'c' => 3), array('a' => 1, 'b' => 3, 'c' => 1), array('a' => 1, 'b' => 3, 'c' => 2), array('a' => 1, 'b' => 3, 'c' => 3), array('a' => 2, 'b' => 1, 'c' => 1), array('a' => 2, 'b' => 1, 'c' => 2), array('a' => 2, 'b' => 1, 'c' => 3), array('a' => 2, 'b' => 2, 'c' => 1), array('a' => 2, 'b' => 2, 'c' => 2), array('a' => 2, 'b' => 2, 'c' => 3), array('a' => 2, 'b' => 3, 'c' => 1), array('a' => 2, 'b' => 3, 'c' => 2), array('a' => 2, 'b' => 3, 'c' => 3), array('a' => 3, 'b' => 1, 'c' => 1), array('a' => 3, 'b' => 1, 'c' => 2), array('a' => 3, 'b' => 1, 'c' => 3), array('a' => 3, 'b' => 2, 'c' => 1), array('a' => 3, 'b' => 2, 'c' => 2), array('a' => 3, 'b' => 2, 'c' => 3), array('a' => 3, 'b' => 3, 'c' => 1), array('a' => 3, 'b' => 3, 'c' => 2), array('a' => 3, 'b' => 3, 'c' => 3));
$this->assertCount(count($expected), $possibilities);
foreach ($expected as $value) {
$this->assertContains($value, $possibilities);
}
}
开发者ID:beberlei,项目名称:JoliCi,代码行数:13,代码来源:MatrixTest.php
示例11: polyfit
function polyfit($X, $Y, $n) {
for($i = 0; $i < sizeof ( $X ); ++ $i)
for($j = 0; $j <= $n; ++ $j)
$A [$i] [$j] = pow ( $X [$i], $j );
for($i = 0; $i < sizeof ( $Y ); ++ $i)
$B [$i] = array (
$Y [$i]
);
$matrixA = new Matrix ( $A );
$matrixB = new Matrix ( $B );
$C = $matrixA->solve ( $matrixB );
return $C->getMatrix ( 0, $n, 0, 1 );
}
开发者ID:nanpeixoto,项目名称:cide,代码行数:13,代码来源:polyfit.php
示例12: testConstructor
/**
* @dataProvider dataProviderMulti
*/
public function testConstructor(array $A, array $R)
{
$D = new DiagonalMatrix($A);
$R = new Matrix($R);
$this->assertInstanceOf('MathPHP\\LinearAlgebra\\DiagonalMatrix', $D);
$this->assertInstanceOf('MathPHP\\LinearAlgebra\\Matrix', $D);
$m = $D->getM();
for ($i = 0; $i < $m; $i++) {
$this->assertEquals($R[$i], $D[$i]);
}
$m = $R->getM();
for ($i = 0; $i < $m; $i++) {
$this->assertEquals($R[$i], $D[$i]);
}
}
开发者ID:markrogoyski,项目名称:math-php,代码行数:18,代码来源:DiagonalMatrixTest.php
示例13: testConstructor
/**
* @dataProvider dataProviderForTestConstructor
*/
public function testConstructor($M, int $n, $V)
{
$M = new VandermondeMatrix($M, $n);
$V = new Matrix($V);
$this->assertInstanceOf('MathPHP\\LinearAlgebra\\VandermondeMatrix', $M);
$this->assertInstanceOf('MathPHP\\LinearAlgebra\\Matrix', $M);
$m = $V->getM();
for ($i = 0; $i < $m; $i++) {
$this->assertEquals($V[$i], $M[$i]);
}
$m = $M->getM();
for ($i = 0; $i < $m; $i++) {
$this->assertEquals($V[$i], $M[$i]);
}
}
开发者ID:markrogoyski,项目名称:math-php,代码行数:18,代码来源:VandermondeMatrixTest.php
示例14: testMap
public function testMap()
{
$callback = function ($elem) {
return $elem * 2;
};
$c = MatrixFactory::fromString('2, 4;
6, 8');
$this->assertEquals($c->getArray(), $this->B->map($callback)->getArray());
}
开发者ID:nosun,项目名称:Matrix,代码行数:9,代码来源:matrix_test.php
示例15: ensureLoaded
/**
* 确保已经加载了配置
*/
public function ensureLoaded()
{
Lazy::init($this->_items, function () {
/** @var CDbConnection $db */
$db = Yii::app()->db;
$items = $db->createCommand()->select(array('key', 'value'))->from('t_config')->queryAll();
return Matrix::from($items)->indexedBy('key')->column('value');
});
}
开发者ID:Clarence-pan,项目名称:org-wiki,代码行数:12,代码来源:Config.php
示例16: getQ
/**
* Assembles Q using the single givens rotations.
*
* @return matrix Q
*/
public function getQ()
{
// Q is an mxm matrix if m is the maximum of the number of rows and thenumber of columns.
$m = max($this->_matrix->columns(), $this->_matrix->rows());
$Q = new Matrix($m, $m);
$Q->setAll(0.0);
// Begin with the identity matrix.
for ($i = 0; $i < $Q->rows(); $i++) {
$Q->set($i, $i, 1.0);
}
for ($j = $this->_matrix->columns() - 1; $j >= 0; $j--) {
for ($i = $this->_matrix->rows() - 1; $i > $j; $i--) {
// Get c and s which are stored in the i-th row, j-th column.
$aij = $this->_matrix->get($i, $j);
$c = 0;
$s = 0;
if ($aij == 0) {
$c = 0.0;
$s = 1.0;
} else {
if (abs($aij) < 1) {
$s = 2.0 * abs($aij);
$c = sqrt(1 - pow($s, 2));
if ($aij < 0) {
$c = -$c;
}
} else {
$c = 2.0 / $aij;
$s = sqrt(1 - pow($c, 2));
}
}
for ($k = 0; $k < $this->_matrix->columns(); $k++) {
$jk = $Q->get($j, $k);
$ik = $Q->get($i, $k);
$Q->set($j, $k, $c * $jk - $s * $ik);
$Q->set($i, $k, $s * $jk + $c * $ik);
}
}
}
return $Q;
}
开发者ID:hoenirvili,项目名称:cn,代码行数:46,代码来源:QRGivens.php
示例17: ex4
public static function ex4()
{
header('Content-type: application/json; charset=utf-8');
//input matricea A , A init
$A = self::getMatrixFromString($_POST['matrice']);
$n = $_POST['n'];
$epsilon = $_POST['epsilon'];
$arrayS = self::getArrayFromString($_POST['arr']);
$b = self::getB($A, $arrayS, $n, $epsilon);
$QR = self::HouseholderDecomposition($A, $epsilon, $n, $b);
$x = self::getX($QR["r"], $n, $QR["b"]);
$matrix = new Matrix($n, $n);
$matrix->fromArray($A);
$QRlibf = array();
$QRlib = new QRGivens($matrix);
$QRlibf['Qlib'] = $QRlib->getQ()->asArray();
$QRlibf['rlib'] = $QRlib->getR()->asArray();
$xlib = self::getX($QR["r"], $n, $QR["b"]);
$vector1 = array();
$ainit = Util::getInit($A);
for ($i = 0; $i < $n; $i++) {
$vector1[$i] = $ainit[$i] * $x[$i] - $b[$i];
}
$norm1 = Util::getNorm($vector1, $n);
$vector2 = array();
for ($i = 0; $i < $n; $i++) {
$vector2[$i] = $ainit[$i] * $xlib[$i] - $b[$i];
}
$norm2 = Util::getNorm($vector2, $n);
$vector3 = array();
for ($i = 0; $i < $n; $i++) {
$vector3[$i] = $x[$i] - $arrayS[$i];
}
$norm3 = Util::getNorm($vector3, $n) / Util::getNorm($arrayS, $n);
$vector4 = array();
for ($i = 0; $i < $n; $i++) {
$vector4[$i] = $xlib[$i] - $arrayS[$i];
}
$norm4 = Util::getNorm($vector4, $n) / Util::getNorm($arrayS, $n);
echo json_encode(array("A" => Util::getStringFromMatrix($A), "epsilon" => $epsilon, "Q" => self::getStringFromMatrix($QR['Q']), "r" => self::getStringFromMatrix($QR['r']), "Qlib" => self::getStringFromMatrix($QRlibf['Qlib']), "rlib" => self::getStringFromMatrix($QRlibf['rlib']), "x" => Util::getStringFromArray($x), "xlib" => Util::getStringFromArray($xlib), "norm1" => $norm1, "norm2" => $norm2, "norm3" => $norm3, "norm4" => $norm4));
}
开发者ID:hoenirvili,项目名称:cn,代码行数:41,代码来源:HomeWork2.php
示例18: findPolynomialFactors
public function findPolynomialFactors($x, $y)
{
$n = count($x);
$data = array();
// double[n][n];
$rhs = array();
// double[n];
for ($i = 0; $i < $n; ++$i) {
$v = 1;
for ($j = 0; $j < $n; ++$j) {
$data[$i][$n - $j - 1] = $v;
$v *= $x[$i];
}
$rhs[$i] = $y[$i];
}
// Solve m * s = b
$m = new Matrix($data);
$b = new Matrix($rhs, $n);
$s = $m->solve($b);
return $s->getRowPackedCopy();
}
开发者ID:Arikito,项目名称:webking.xt,代码行数:21,代码来源:LagrangeInterpolation2.php
示例19: log_in
public function log_in()
{
$objdata = new Database();
$sth = $objdata->prepare('SELECT * FROM users WHERE logUser = :login AND pasUser = :pass');
$sth->execute(array(':login' => $_POST['Usern'], ':pass' => $_POST['passU']));
$data = $sth->fetch();
$count = $sth->rowCount();
if ($count > 0) {
if ($data['id_matrix'] == 0) {
$objMatrix = new Matrix();
$matrix = $objMatrix->create_matrix();
$objMatrix->insert_matri($matrix);
$datos = $objMatrix->return_matrix();
$objMatrix->matrix_assign($data['idUser'], $datos[0]['id_matrix']);
} else {
header('location: ' . URL . 'matrix.php?m=' . $data['id_matrix'] . '&u=' . $data['idUser']);
}
} else {
header('location: ' . URL . 'index.php?iderr=1');
}
}
开发者ID:dareyesm,项目名称:paginadorPHP,代码行数:21,代码来源:users.php
示例20: correlation
/**
* Compute the covariance matrix for the row vectors.
* @param $matrix Could be RealMatrix or SparseMatrix.
* @return Matrix a new m by m covariance matrix.
* don't have to return by ref, because the engine will take care of it.
* Note that no matter what's the input matrix, the returned matrix is always a sparse matrix.
*/
static function correlation($matrix)
{
$vectors = $matrix->row_vectors();
$m = $matrix->row;
// dimension of the correlation matrix
$cor_matrix = Matrix::create('SparseMatrix', $m, $m);
for ($v1 = 0; $v1 < $m; $v1++) {
for ($v2 = $v1; $v2 < $m; $v2++) {
if (isset($vectors[$v1]) && isset($vectors[$v2])) {
// note, some value (such as std) is cached, so it won't be too much performance problem.
$cor = $vectors[$v1]->correlation($vectors[$v2]);
if (!is_nan($cor)) {
$cor_matrix->set($v1, $v2, $cor);
$cor_matrix->set($v2, $v1, $cor);
}
}
}
}
return $cor_matrix;
}
开发者ID:sonamsingh28,项目名称:drupalmumbai,代码行数:27,代码来源:Matrix.php
注:本文中的Matrix类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论