8000 Added demo for mc29 module · PythonOptimizers/HSL.py@b8aeaef · GitHub
[go: up one dir, main page]

Skip to content

Commit b8aeaef

Browse files
committed
Added demo for mc29 module
1 parent 177cae5 commit b8aeaef

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

doc/source/contents.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
introduction
1313
installation
1414
ordering
15+
scaling
1516
solvers
1617
examples
1718

doc/source/scaling.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. Description of scaling module
2+
.. _scaling-page:
3+
4+
===================================
5+
Scaling method for sparse matrices
6+
===================================
7+
8+
9+
10+
The :mod:`mc29` Module
11+
======================
12+
13+
.. _mc29-section:
14+
15+
Example
16+
-------
17+
18+
.. literalinclude:: ../../examples/demo_mc29.py
19+
:linenos:
20+
21+
Output
22+
23+
.. code-block:: python
24+
25+
orignal values:
26+
[ 1.60000000e+04 1.00000000e+02 1.40000000e+04 6.00000000e+00
27+
9.00000000e+02 1.10000000e+05]
28+
29+
row scaling factors:
30+
[ 2.17526613e+00 5.55712076e+02 7.35847733e-02 3.90868730e-01]
31+
32+
column scaling factors:
33+
[ 0.0083316 0.00023411 0.00014055]
34+
35+
scaled values
36+
[ 0.87899243 1.81234539 1.28108793 0.78058654 0.55177121 1.13766623]

examples/demo_mc29.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"Exemple from MC29 spec sheet: http://www.hsl.rl.ac.uk/specs/mc29.pdf"
2+
3+
from hsl.scaling._mc29 import mc29ad
4+
import numpy as np
5+
6+
irow = np.array([3,0,3,1,2,2], dtype=np.int32)
7+
jcol = np.array([2,0,1,1,0,2], dtype=np.int32)
8+
values = np.array([16000, 100, 14000, 6, 900, 110000], dtype=np.float64)
9+
print 'orignal values:'
10+
print values
11+
12+
# Obtain row and column scaling
13+
row_scale, col_scale, ifail = mc29ad(4, 3, values, irow+1, jcol+1)
14+
15+
if ifail==-1:
16+
raise ValueError("m < 1 or n < 1")
17+
elif ifail==-2:
18+
raise ValueError("number of non zero elemnts < 1")
19+
20+
# row_scale and col_scale contain in fact the logarithms of the
21+
# scaling factors.
22+
row_scale = np.exp(row_scale)
23+
col_scale = np.exp(col_scale)
24+
25+
print '\nrow scaling factors:'
26+
print row_scale
27+
28+
print '\ncolumn scaling factors:'
29+
print col_scale
30+
31+
# Apply row and column scaling to constraint matrix A.
32+
values *= row_scale[irow]
33+
values *= col_scale[jcol]
34+
35+
print '\nscaled values'
36+
print values

0 commit comments

Comments
 (0)
0