IPython-Notebook

Demo of pyhasse.lpom

Aim of the programm

LPOM stands for Local Partial Order Model.

LPOM0 and LPOMext are approximations to calculate the average height, hav, of partially ordered sets (posets).

If not allredy done

Comment out or delete the following line if the module is installed.

In [24]:
#!pip install pyhasse.lpom

import all nessesary libraries

In [25]:
import pathlib
from pyhasse.core.csv_io import CSVReader
from pyhasse.core.order import Order
from pyhasse.lpom.calc import LPOM
import json
import random
from IPython.core.display import display, HTML
import pandas as pd
from string import Template
In [26]:
TESTFILENAME = '/csvdata/a-equiv.txt'
prefs={
    'start': 0,
    'stop': 3,
    'user_list' : [],
    'labelLen': 3,
    'actwidth': 550,
    'actheight': 200
}

HERE = pathlib.Path('__file__').parent
csv = CSVReader(fn=str(HERE) + TESTFILENAME, ndec=3)
red = csv.calc_reduced_system()
order = Order(csv.dmred,
              csv.redrows,
              csv.cols)
zeta = order.calc_relatmatrix(csv.dmred,
                              csv.redrows,
                              csv.cols)
redrows = csv.redrows
down = order.calc_downset(zeta, redrows)
up = order.calc_upset(zeta, redrows)

Some basic data

In [27]:
print(csv.rows)
print(csv.cols)
print(csv.prop)
print(csv.obj)
print(csv.objred)
print(csv.data)
8
3
['q1', 'q2', 'q3']
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
['a', 'c', 'd', 'e', 'h']
[[1.0, 1.0, 2.0], [1.0, 1.0, 2.0], [3.0, 2.0, 1.0], [1.0, 2.0, 3.0], [4.0, 4.0, 4.0], [1.0, 1.0, 2.0], [4.0, 4.0, 4.0], [9.0, 9.0, 9.0]]
In [28]:
incomp = order.calc_incompset(zeta, redrows)
order.calc_incomp(zeta, redrows)
down = order.calc_downset(zeta, redrows)
up = order.calc_upset(zeta, redrows)
print(up)
print(down)
[[0, 2, 3, 4], [1, 3, 4], [2, 3, 4], [3, 4], [4]]
[[0], [1], [0, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]]
In [29]:
lpom2 = LPOM()
In [30]:
hav0 = lpom2.calc_hav(down, incomp, redrows)
In [31]:
hav1 = lpom2.calc_hav_ext(down, up, incomp, redrows)
print(hav1)
[1.33, 2.0, 2.67, 4, 5]

Outpup "Averaged height" as table

In [32]:
from IPython.display import HTML, display
from pyhasse.core.tables import HTMLTable

data = []
for idx, item in enumerate(csv.objred):
    data.append([item, hav1[idx]])
tab = HTMLTable(data)
display(HTML(tab.table2html()))
a 1.33
c 2.0
d 2.67
e 4
h 5

Objects averaged height0

In [33]:
eqact = csv.eqm
fext0 = csv.weak(csv.obj, csv.objred, eqact, hav1)
data = []
for idx, item in enumerate(csv.obj):
    data.append([item, fext0[idx]])
tab = HTMLTable(data)
display(HTML(tab.table2html()))
a 1.33
b 1.33
c 2.0
d 2.67
e 4
f 1.33
g 4
h 5

Output as graph

Comming soon....