Re: Control stript which is runing in background.

2021-01-02 Thread jak

Il 02/01/2021 01:07, Alan Bawden ha scritto:

jak  writes:

Il 01/01/2021 06:23, Alan Bawden ha scritto:
> jak  writes:
>
> Running the command:
>
> $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > 
cmdpipe
>
> the three texts do not mix
>
> The three texts do not mix as long at the contents of bible.txt is short
> enough (and provided `cat' only calls `write' once).  In the POSIX
> specification, the manual page for the `write' system call describes
> writing to a pipe or FIFO as follows:
>
>Write requests of {PIPE_BUF} bytes or less shall not be interleaved
>with data from other processes doing writes on the same pipe.  Writes
>of greater than {PIPE_BUF} bytes may have data interleaved, on
>arbitrary boundaries, with writes by other processes, whether or not
>the O_NONBLOCK flag of the file status flags is set.
>
Ok. And...
 ...Running the command:

 $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > 
cmdpipe

 the three texts do not mix

Saying it again doesn't make it any more true.  If bible.txt is large
enough, they most definitely DO mix!  Just to make sure I wasn't missing
something, I tested your exact command before I sent my previous reply.
They mixed.



This is really strange. On which system did you test? unix, linux or a
surrogate (cygwin, msys)? I asked this because bible.txt is 4.25MB size
(https://github.com/mxw/grmr/blob/master/src/finaltests/bible.txt)...
and the OP needs to send only commands (I hope smaller than the bible).
--
https://mail.python.org/mailman/listinfo/python-list


Re: Control stript which is runing in background.

2021-01-02 Thread jak

Il 02/01/2021 01:07, Alan Bawden ha scritto:

jak  writes:

Il 01/01/2021 06:23, Alan Bawden ha scritto:
> jak  writes:
>
> Running the command:
>
> $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > 
cmdpipe
>
> the three texts do not mix
>
> The three texts do not mix as long at the contents of bible.txt is short
> enough (and provided `cat' only calls `write' once).  In the POSIX
> specification, the manual page for the `write' system call describes
> writing to a pipe or FIFO as follows:
>
>Write requests of {PIPE_BUF} bytes or less shall not be interleaved
>with data from other processes doing writes on the same pipe.  Writes
>of greater than {PIPE_BUF} bytes may have data interleaved, on
>arbitrary boundaries, with writes by other processes, whether or not
>the O_NONBLOCK flag of the file status flags is set.
>
Ok. And...
 ...Running the command:

 $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > 
cmdpipe

 the three texts do not mix

Saying it again doesn't make it any more true.  If bible.txt is large
enough, they most definitely DO mix!  Just to make sure I wasn't missing
something, I tested your exact command before I sent my previous reply.
They mixed.


You're right it's mixed. I tried this:
terminal 1:

$ python3 pmkfifo.py > output.txt

terminal 2:

cat bible.txt > mypipe & cat bible.txt > mypipe & cat bible.txt > mypipe

result:

-rw-rw-r-- 1 jak jak  4351187 gen  1 02:56 bible.txt
prw-rw-r-- 1 jak jak0 gen  2 11:40 mypipe
-rw-rw-r-- 1 jak jak 13053561 gen  2 11:40 output.txt
-rw-rw-r-- 1 jak jak  237 gen  1 02:46 pmkfifo.py

then I split ouput.txt:

$ split -n 3 -d output.txt result

result:

-rw-rw-r-- 1 jak jak  4351187 gen  1 02:56 bible.txt
prw-rw-r-- 1 jak jak0 gen  2 11:40 mypipe
-rw-rw-r-- 1 jak jak 13053561 gen  2 11:40 output.txt
-rw-rw-r-- 1 jak jak  237 gen  1 02:46 pmkfifo.py
-rw-rw-r-- 1 jak jak  4351187 gen  2 11:41 result00
-rw-rw-r-- 1 jak jak  4351187 gen  2 11:41 result01
-rw-rw-r-- 1 jak jak  4351187 gen  2 11:41 result02

but:

$ cmp result00 result01
result00 result01 differ: byte 1, line 1

$ cmp result01 result02
result01 result02 differ: byte 1, line 1

...but not happy I wanted to try sure that each process used a single 
write and I wrote this program in C:


int main()
{
FILE *fp;
long len, readed;
char *buffer;

if((fp = fopen("bible.txt", "rt")) == NULL)
return -1;
// get file size
if(!fseek(fp, 0, SEEK_END))
{
len = ftell(fp);
}
else
return -1;
// build buffer
   if((buffer = malloc(len)) == NULL)
return -1;
// reset position
if(fseek(fp, 0, SEEK_SET))
return -1;
if((readed = fread(buffer, len, 1, fp)) != 1)
return -1;
if((fwrite(buffer, len, 1, stdout)) < 1)
return -1;
fflush(stdout);
free(buffer);
fclose(fp);
return 0;
}

... and runned:

$ ./mycat > mypipe & ./mycat > mypipe & ./mycat > mypipe

I, however, got the same result.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Control stript which is runing in background.

2021-01-02 Thread jak

PS:
difference starts after 64K block
--
https://mail.python.org/mailman/listinfo/python-list


Re: Control stript which is runing in background.

2021-01-02 Thread Alan Bawden
jak  writes:

   Il 02/01/2021 01:07, Alan Bawden ha scritto:
   > jak  writes:
   >
   > Il 01/01/2021 06:23, Alan Bawden ha scritto:
   > > jak  writes:
   > >
   > > Running the command:
   > >
   > > $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat 
bible.txt > cmdpipe
   > >
   > > the three texts do not mix
   > >
   > > The three texts do not mix as long at the contents of bible.txt is 
short
   > > enough (and provided `cat' only calls `write' once).  In the POSIX
   > > specification, the manual page for the `write' system call describes
   > > writing to a pipe or FIFO as follows:
   > >
   > >Write requests of {PIPE_BUF} bytes or less shall not be 
interleaved
   > >with data from other processes doing writes on the same pipe.  
Writes
   > >of greater than {PIPE_BUF} bytes may have data interleaved, on
   > >arbitrary boundaries, with writes by other processes, whether or 
not
   > >the O_NONBLOCK flag of the file status flags is set.
   > >
   > ...  Just to make sure I wasn't missing
   > something, I tested your exact command before I sent my previous reply.
   > They mixed.
   >

   This is really strange. On which system did you test? unix, linux or a
   surrogate (cygwin, msys)? I asked this because bible.txt is 4.25MB size
   (https://github.com/mxw/grmr/blob/master/src/finaltests/bible.txt)...
   and the OP needs to send only commands (I hope smaller than the bible).

I tested it on both Linux and FreeBSD.  My test data was a 289M file I
happend to have handy.  I didn't try to see how much smaller that file
could be to still see mixing, but I can tell you that on FreeBSD
PIPE_BUF is 512 bytes and on Linux PIPE_BUF is 4096 bytes.  Recent
versions of POSIX apparently require PIPE_BUF to be at least 512.  (My
older copy of POSIX doesn't mention any lower bound at all!)

So as long as the OP's commands are no longer than 512 bytes, and as
long as they are careful to send commands in a single call to write(),
and as long as the commands don't require a reply, they can get away
with using a pipe/FIFO.  (Or maybe they can know that there will only
ever be one client.)

-- 
Alan Bawden
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Control stript which is runing in background.

2021-01-02 Thread Greg Ewing

On 3/01/21 12:30 am, Alan Bawden wrote:

So as long as the OP's commands are no longer than 512 bytes, and as
long as they are careful to send commands in a single call to write(),


Also note that's one write() system call, which may or may not
correspond to one Python write() call.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Kalman Filter for predicting randomized chaos in jupyter labs

2021-01-02 Thread Housebyte Bestofnet
As a start to this forum Ive included this wonderful peice of Vanilla code - 
[b]The Kalman Filter[/b]
I downloaded from github this wonderfully elegant Kalman filter : 
[url]https://github.com/hbcbh1999/kalman-filter[/url] Its a really nice and 
simple implementation using the equations you can find on wikipedia 
[url]https://en.wikipedia.org/wiki/Kalman_filter[/url] It looks really awsome 
when applied to the 
[url=http://spacetripping.just4books.co.uk/HiRobot/viewtopic.php?f=7&t=6]Arneodo
 XS dimension Chaotic Attractor[/url] with added noise. Enjoy. 

[color=#FF]Works in Python 2.7 or Python 3.0+[/color]

[code]#!/usr/bin/env python
# coding: utf-8

# In[1]:


get_ipython().magic(u'matplotlib inline')
import numpy as np


# In[2]:


class KalmanFilter(object):
def __init__(self, F = None, B = None, H = None, Q = None, R = None, P = 
None, x0 = None):

if(F is None or H is None):
raise ValueError("Set proper system dynamics.")

self.n = F.shape[1]
self.m = H.shape[1]

self.F = F
self.H = H
self.B = 0 if B is None else B
self.Q = np.eye(self.n) if Q is None else Q
self.R = np.eye(self.n) if R is None else R
self.P = np.eye(self.n) if P is None else P
self.x = np.zeros((self.n, 1)) if x0 is None else x0

def predict(self, u = 0):
self.x = np.dot(self.F, self.x) + np.dot(self.B, u)
self.P = np.dot(np.dot(self.F, self.P), self.F.T) + self.Q
return self.x

def update(self, z):
y = z - np.dot(self.H, self.x)
S = self.R + np.dot(self.H, np.dot(self.P, self.H.T))
K = np.dot(np.dot(self.P, self.H.T), np.linalg.inv(S))
self.x = self.x + np.dot(K, y)
I = np.eye(self.n)
self.P = np.dot(np.dot(I - np.dot(K, self.H), self.P), 
(I - np.dot(K, self.H)).T) + np.dot(np.dot(K, self.R), K.T)
return y


def arneodo(x, y, z, a=-5.5, b=3.5, c=-1):
'''
Given:
   x, y, z: a point of interest in three dimensional space
   s, r, b: parameters defining the lorenz attractor
Returns:
   x_dot, y_dot, z_dot: values of the lorenz attractor's partial
   derivatives at the point x, y, z
'''
x_dot = y
y_dot = z
z_dot = -a*x-b*y-z+c*(x**3)
return x_dot, y_dot, z_dot


dt = 0.01
num_steps = 7000

# Need one more for the initial values
xs = np.empty(num_steps + 1)
ys = np.empty(num_steps + 1)
zs = np.empty(num_steps + 1)

# Set initial values
xs[0], ys[0], zs[0] = (0.1, 0, 0.1)

# Step through "time", calculating the partial derivatives at the current point
# and using them to estimate the next point
for i in range(num_steps):
x_dot, y_dot, z_dot = arneodo(xs[i], ys[i], zs[i])
xs[i + 1] = xs[i] + (x_dot * dt)
ys[i + 1] = ys[i] + (y_dot * dt)
zs[i + 1] = zs[i] + (z_dot * dt)

def example():
dt = 1.0/60
F = np.array([[1, dt, 0], [0, 1, dt], [0, 0, 1]]).reshape(3,3)
H = np.array([1, 0, 0]).reshape(1, 3)
Q = np.array([[0.05, 0.05, 0.0], [0.05, 0.05, 0.0], [0.0, 0.0, 
0.0]]).reshape(3,3)
R = np.array([0.5]).reshape(1, 1)
Error = np.empty(7002)
  
x = np.linspace(-10, 10, 100)
measurements = xs + np.random.normal(0, 2, 7001)
#- (x**2 + 2*x - 2)
kf = KalmanFilter(F = F, H = H, Q = Q, R = R)
predictions = []

n=0
for z in measurements:
n+=1
predictions.append(np.dot(H,  kf.predict())[0])
Error[n] =kf.update(z)
 


import matplotlib.pyplot as plt
plt.plot(range(len(Error)), Error, label = 'Error')
plt.plot(range(len(measurements)), measurements, label = 'Measurements')
plt.plot(range(len(predictions)), np.array(predictions), label = 'Kalman 
Filter Prediction')
plt.plot(range(len(xs)), xs, label = 'Signal')
plt.legend()
plt.show()

if __name__ == '__main__':
example()

[/code]

The proceeding discussions will be about the use of the following matrices in 
the Kalman Filter, what form they may take and how they can be derived from the 
distribution we are modelling :

dt = 1.0/60
F = np.array([[1, dt, 0], [0, 1, dt], [0, 0, 1]]).reshape(3,3)   #State 
Transition Model
H = np.array([1, 0, 0]).reshape(1, 3)  
#Observation Model
Q = np.array([[0.05, 0.05, 0.0], [0.05, 0.05, 0.0], [0.0, 0.0, 
0.0]]).reshape(3,3)   #Covariance Matrix
R = np.array([0.5]).reshape(1, 1)[/code] #Covariance Matrix

[url=https://en.wikipedia.org/wiki/Autoregressive_integrated_moving_average]ARIMA
 - Wikipedia[/url]

[img]http://spacetripping.just4books.co.uk/HiRobot/output_4_0.png[/img]

Original source:
http://spacetripping.just4books.co.uk/HiRobot/viewtopic.php?f=7&t=3
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A random word from one of two lists

2021-01-02 Thread Bischoop
On 2021-01-02, Stefan Ram  wrote:
>
>   The following might /not/ be good programming style,
>   but addresses the idea to choose a "variable".
>
I kinda like the below one.
> import random
> animal = ['koala', 'kangaroo']
> fruit = ['banana', 'apple']
> kinds = ['animal','fruit']
> variable = random.choice( kinds )
> result = random.choice( globals()[ variable ])
> print( result )
>


>   Otherweise, I'd go this way without a dictionary.
> import random
> animal = ['koala', 'kangaroo']
> fruit = ['banana', 'apple']
> kinds = [animal,fruit]
> kind = random.choice( kinds )
> result = random.choice( kind )
> print( result )
>
I had that solution in mind but I thought that one is not good
programming style or not Pythonin :-)


--
Thanks
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Plotting in python for Monte Carlo Method

2021-01-02 Thread dn via Python-list
On 1/2/21 12:17 AM, Meghna Karkera wrote:
> Dear Respected Sir
> 
> May I request you to help me plot the number of histories versus standard
> deviation along with mean for integral of 2x dx from 0 to 5 abtained using
> the Monte Carlo python program.
> 
> I've calculated the integral of 2x dx from 0 to 5 using the Monte Carlo
> method described in the following link. https://youtu.be/WAf0rqwAvgg


Welcome to the list. Let's try to clarify a few points:-

Is this request connected with a course of study? If so, which one?

We don't 'do homework' but are happy to help. What code have you written
so far, and which part is not working?
(please copy-paste exact code and error messages, after reducing the
code to its shortest reproducible state)

NB there is also the Python-Tutor Discussion List which is specifically
for trainees' and trainers' use.


Contrarily, if you are looking for someone to write code for you, then
there are likely many 'here' who will be happy to quote an hourly-rate.
-- 
Regards =dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: unicode 2.8

2021-01-02 Thread Terry Reedy

On 1/1/2021 3:48 PM, [email protected] wrote:

Terry Reedy  wrote:

On 12/31/2020 9:36 AM, [email protected] wrote:

unicode is a simple python command line utility that displays
properties for a given unicode character, or searches
unicode database for a given name.

...

Changes since previous versions:

   * display ASCII table (either traditional with --ascii or the new
 EU–UK Trade and Cooperation Agreement version with --brexit-ascii)


The latter option implied to me that the agreement defines an 
intentional variation on standard ASCII.  I immediately wondered whether 
they had changed the actual 7-bit ascii code, which would be egregiously 
bad, or made yet another variation of 8-bit 'extended ascii', perhaps to 
ensure inclusion both the pound and euro signs.


So I googled 'brexit ascii'.  And was surprised to discover that there 
is no such thing as 'brexit ascii', just yet another cock-up in text 
preparation.  (I have seen worse when a digital text of mine was mangled 
during markup.  Fortunately, I was allowed to read the page proofs.  But 
I still don't understand how spelling errors were introduced within 
words I had spelled correctly.)



Are you reproducing it with bugs included?
How is that of any use to anyone?


I followed this with links to justify my claim and question:

A tweet linking the treaty annex page
https://twitter.com/thejsa_/status/1343291595899207681

A stackoverflow question and discussion of the bugs and oddities.
https://politics.stackexchange.com/questions/61178/why-does-the-eu-uk-trade-deal-have-the-7-bit-ascii-table-as-an-appendix

In the latter are mentions of other text, perhaps copy-pasted from the 
1990s recommending the now deprecated SHA1 and referring to Netscape 
Navigator 4 as a modern browser.  Clearly, in the rush to finish, the 
annex was not properly reviewed by current technical experts.



Including the (correct) ASCII table has been a long term, low priority -
I am using ascii(1) utility reasonably often and it makes sense to
reproduce this functionality.

And when implementing this, it was a no-brainer to include also the
brexit varian (verbatim).


I assume you meant 'variation' and not Varian, the maker of scientific 
instruments.


But why do you consider it a no-brainer to include nonsense in your 
program and mislead people?  People already have enough trouble dealing 
with text coding.



After all, given the blood and sweat and tears
shed during the negotiations, I am sure each and every line of the
Agreement has been combed and (re)negotiated over and over by experienced
negotiators and verified an army of experts in the fields 


What are we supposed to make of this?  That you already knew that 
'brexit-ascii' is nonsense?



--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: unicode 2.8

2021-01-02 Thread Chris Angelico
On Sun, Jan 3, 2021 at 10:28 AM Terry Reedy  wrote:
> > And when implementing this, it was a no-brainer to include also the
> > brexit varian (verbatim).
>
> I assume you meant 'variation' and not Varian, the maker of scientific
> instruments.

I assumed simple typo for "variant"

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Mauritius Usergroup - End of Year report 2020

2021-01-02 Thread Abdur-Rahmaan Janhangeer
Greetings list,

Here's our usergroup's end of year report for 2020:
Happy reading!

https://www.pymug.com/assets/pymug_end_of_year_2020_v2.pdf

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Mauritius Usergroup - End of Year report 2020

2021-01-02 Thread dn via Python-list
On 1/3/21 5:01 PM, Abdur-Rahmaan Janhangeer wrote:
> Greetings list,
> 
> Here's our usergroup's end of year report for 2020:
> Happy reading!
> 
> https://www.pymug.com/assets/pymug_end_of_year_2020_v2.pdf


Well done @A-R!
-- 
Regards =dn
-- 
https://mail.python.org/mailman/listinfo/python-list