Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Entropy requires no maintenance. -- Markoff Chaney


devel / comp.programming / Re: Paragraph Wrapping

SubjectAuthor
* Paragraph WrappingStefan Ram
+* Paragraph WrappingNoel Duffy
|+- Paragraph WrappingStefan Ram
|+* Paragraph WrappingStefan Ram
||`* Paragraph WrappingRichard Heathfield
|| `* Paragraph WrappingStefan Ram
||  +- Paragraph WrappingStefan Ram
||  `- Paragraph WrappingStefan Ram
|`- Paragraph WrappingY A
+- Paragraph WrappingRichard Heathfield
`- Paragraph WrappingBen Bacarisse

1
Paragraph Wrapping

<wrap-20230126195034@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=4024&group=comp.programming#4024

  copy link   Newsgroups: comp.programming
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.programming
Subject: Paragraph Wrapping
Date: 26 Jan 2023 19:50:39 GMT
Organization: Stefan Ram
Lines: 65
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <wrap-20230126195034@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de YyICFs/GSngrXLFf52tvNwS0GdoIFz9S7ohiad6VF+BTrE
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 26 Jan 2023 19:50 UTC

To wrap a paragraph, I wrote a Python script that searched for
the best wrap, given a quality function that included penalties
for interpunction near the end of a line (but not at the end)
or adjacent lines that differed greatly in length.

It worked, but as the number of lines approached ten, it became
painfully slow.

By an incredible twist of fate, I came across a chapter of
a book that explained dynamic programming and how to use it
to reduce the complexity of global paragraph wrapping from
exponential to quadratic!

So I modified my script yesterday, and today all the paragraphs
you read here are wrapped by the new script, because I configured
my editor to run paragraphs through this script whenever I press
a certain sequence of keys.

So how does this work?

An exponential paragraph wrapping algorithm tries every
combination of break points and gets a quality score for each.
I think my first program must have looked like this. I may have
eliminated some obviously bad line breaks, but basically it
must have been an exponential algorithm.

The dynamic programming algorithm, as I understand it, works like
this and can still find the global optimum: I have a loop that
goes through each possible break point just once (which would be
linear). Then this loop has an inner loop that goes through each
previous breakpoint (now it's quadratic). The previous breakpoints
have already been evaluated. So it can easily find the best
combination of a previous breakpoint and a possible break at the
current position. This is the quality score for a break at the
current position. Finally, you start at the break point just after
the last word of the paragraph and go from there to all the best
preceding break points to identify the lines of the result.

However, it seems to me that I am a bit limited in the quality
measure function, because this function seems to support best
quality measures that only consider the current line and maybe the
combination of the current line with the preceding line. The global
quality measure function I had before could also easily measure
such global quantities as the standard deviation of the lengths of
all the lines of the result. This is not accessible to the dynamic
programming algorithm as I understand it, because when it is in the
middle of the paragraph, it does not yet know the lengths of all
the lines, and when it is at the end of the paragraph, it cannot
change decisions that have already been made.

The same book also gave another problem that could supposedly be
solved using dynamic programming: In a restaurant you are shown
five dishes in a sequence, and you can choose one to eat. You are
shown only one dish at a time and do not know which dish will be
shown next. Once you accept or reject a dish, you cannot go back on
your decision. If you do not choose any of the first four dishes,
this means that you would inevitably eat the last one. How should
you proceed to maximize the probability of getting the best dish?

The solution given in the book begins by explaining that you
assign a quality score between 0 and 1 to each dish you see.
So the question is how to proceed to maximize the probability
of eating a dish with a quality score as high as possible . . .

Re: Paragraph Wrapping

<tqumg4$1aqqf$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=4025&group=comp.programming#4025

  copy link   Newsgroups: comp.programming
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: uaigh@icloud.com (Noel Duffy)
Newsgroups: comp.programming
Subject: Re: Paragraph Wrapping
Date: Fri, 27 Jan 2023 09:06:28 +1300
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <tqumg4$1aqqf$1@dont-email.me>
References: <wrap-20230126195034@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 26 Jan 2023 20:06:29 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4c3176d569b06e10fe1617434ffa06ee";
logging-data="1403727"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RTZDtRtxlnxdRuy24rXZDU3bNqDlu9AM="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Cancel-Lock: sha1:T4x0iI1KicUDTx2PbfrCAYl36rE=
In-Reply-To: <wrap-20230126195034@ram.dialup.fu-berlin.de>
Content-Language: en-US
 by: Noel Duffy - Thu, 26 Jan 2023 20:06 UTC

On 27/01/23 08:50, Stefan Ram wrote:
> By an incredible twist of fate, I came across a chapter of
> a book that explained dynamic programming and how to use it
> to reduce the complexity of global paragraph wrapping from
> exponential to quadratic!

Well don't keep us in suspense! What's the book?

Re: Paragraph Wrapping

<book-20230126211858@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=4026&group=comp.programming#4026

  copy link   Newsgroups: comp.programming
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.programming
Subject: Re: Paragraph Wrapping
Date: 26 Jan 2023 20:20:12 GMT
Organization: Stefan Ram
Lines: 12
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <book-20230126211858@ram.dialup.fu-berlin.de>
References: <wrap-20230126195034@ram.dialup.fu-berlin.de> <tqumg4$1aqqf$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de N/UYYAAKNtKK5LhAXO5rGgqOKH8LimVsnY1m9g87yTmOfj
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 26 Jan 2023 20:20 UTC

Noel Duffy <uaigh@icloud.com> writes:
>On 27/01/23 08:50, Stefan Ram wrote:
>>By an incredible twist of fate, I came across a chapter of
>>a book that explained dynamic programming and how to use it
>>to reduce the complexity of global paragraph wrapping from
>>exponential to quadratic!
>Well don't keep us in suspense! What's the book?

Ok, but since it contains a solution to the food dish task,
I may wait a week.

Re: Paragraph Wrapping

<tquplb$1a9o0$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=4027&group=comp.programming#4027

  copy link   Newsgroups: comp.programming
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rjh@cpax.org.uk (Richard Heathfield)
Newsgroups: comp.programming
Subject: Re: Paragraph Wrapping
Date: Thu, 26 Jan 2023 21:00:27 +0000
Organization: Fix this later
Lines: 53
Message-ID: <tquplb$1a9o0$1@dont-email.me>
References: <wrap-20230126195034@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 26 Jan 2023 21:00:28 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="a47fbe1d7f57625fe964d7e3374694a5";
logging-data="1386240"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4H7+GDbtoS+N+pBHROl/atRYmcNc7TlmQpGHNTmZFYw=="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:MOBHKB6FlPiSdgJ1w2A9Hdy4Tj8=
In-Reply-To: <wrap-20230126195034@ram.dialup.fu-berlin.de>
Content-Language: en-GB
 by: Richard Heathfield - Thu, 26 Jan 2023 21:00 UTC

On 26/01/2023 7:50 pm, Stefan Ram wrote:
> The same book also gave another problem that could supposedly be
> solved using dynamic programming: In a restaurant you are shown
> five dishes in a sequence, and you can choose one to eat. You are
> shown only one dish at a time and do not know which dish will be
> shown next. Once you accept or reject a dish, you cannot go back on
> your decision. If you do not choose any of the first four dishes,
> this means that you would inevitably eat the last one. How should
> you proceed to maximize the probability of getting the best dish?
>
> The solution given in the book begins by explaining that you
> assign a quality score between 0 and 1 to each dish you see.
> So the question is how to proceed to maximize the probability
> of eating a dish with a quality score as high as possible . . .

0123456789 spoiler space
0123456789 spoiler spac
0123456789 spoiler spa
0123456789 spoiler sp
0123456789 spoiler s
0123456789 spoiler
0123456789 spoiler
0123456789 spoile
0123456789 spoil
0123456789 spoi
0123456789 spo
0123456789 sp
0123456789 s
0123456789
0123456789
012345678
01234567
0123456
012345
01234
0123
012
01

Reject (but score) the first two dishes, and then accept the
first dish that scores better than any you have yet seen (or the
last if you must and are very hungry).

This algorithm will pick the best of five dishes about seven
times in twenty visits.

--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

Re: Paragraph Wrapping

<87o7qkwz3o.fsf@bsb.me.uk>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=4028&group=comp.programming#4028

  copy link   Newsgroups: comp.programming
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.programming
Subject: Re: Paragraph Wrapping
Date: Fri, 27 Jan 2023 01:22:19 +0000
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <87o7qkwz3o.fsf@bsb.me.uk>
References: <wrap-20230126195034@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="60014a0063bb2d5830bbe2489c026e03";
logging-data="1497578"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OYSJBojVELvS9aiNG7vmTA8AU8pySwX8="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:od94sYCWNOuQu9VrB5diaB+KWvM=
sha1:Q+zdROLHV5HuLaa/5ataglCwNE4=
X-BSB-Auth: 1.04305b3b24603825f755.20230127012219GMT.87o7qkwz3o.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 27 Jan 2023 01:22 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> To wrap a paragraph, I wrote a Python script that searched for
> the best wrap, given a quality function that included penalties
> for interpunction near the end of a line (but not at the end)
> or adjacent lines that differed greatly in length.
>
> It worked, but as the number of lines approached ten, it became
> painfully slow.
>
> By an incredible twist of fate, I came across a chapter of
> a book that explained dynamic programming and how to use it
> to reduce the complexity of global paragraph wrapping from
> exponential to quadratic!

The TeX Book describes two-level algorithm to calculate optimal line
breaks in paragraphs and the optimal page breaks.

--
Ben.

Re: Paragraph Wrapping

<book-20230202220128@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=4037&group=comp.programming#4037

  copy link   Newsgroups: comp.programming
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.programming
Subject: Re: Paragraph Wrapping
Date: 2 Feb 2023 21:02:06 GMT
Organization: Stefan Ram
Lines: 18
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <book-20230202220128@ram.dialup.fu-berlin.de>
References: <wrap-20230126195034@ram.dialup.fu-berlin.de> <tqumg4$1aqqf$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de RRjAyevnxr08z3YcgScxFQ3BfK2JX5/qQ9J4SBv8xophd4
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 2 Feb 2023 21:02 UTC

Noel Duffy <uaigh@icloud.com> writes:
>On 27/01/23 08:50, Stefan Ram wrote:
>>By an incredible twist of fate, I came across a chapter of
>>a book that explained dynamic programming and how to use it
>>to reduce the complexity of global paragraph wrapping from
>>exponential to quadratic!
>Well don't keep us in suspense! What's the book?

|The Computer Science of TeX and LaTeX;
|based on CS 594, fall 2004, University of Tennessee
| |Victor Eijkhout
|Texas Advanced Computing Center
|The University of Texas at Austin
| |2012

Re: Paragraph Wrapping

<trhas0$j6m3$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=4038&group=comp.programming#4038

  copy link   Newsgroups: comp.programming
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rjh@cpax.org.uk (Richard Heathfield)
Newsgroups: comp.programming
Subject: Re: Paragraph Wrapping
Date: Thu, 2 Feb 2023 21:44:32 +0000
Organization: Fix this later
Lines: 26
Message-ID: <trhas0$j6m3$1@dont-email.me>
References: <wrap-20230126195034@ram.dialup.fu-berlin.de>
<tqumg4$1aqqf$1@dont-email.me> <book-20230202220128@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 2 Feb 2023 21:44:32 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="95ec143fa46e861235ab5d8118f89ce3";
logging-data="629443"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19686sZci4iPXyaL9fTqg+CC0F/tXCC76o4VANsUnuPeQ=="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:Ac5E6xb2yo4DpP5H/QYa2uu295c=
Content-Language: en-GB
In-Reply-To: <book-20230202220128@ram.dialup.fu-berlin.de>
 by: Richard Heathfield - Thu, 2 Feb 2023 21:44 UTC

On 02/02/2023 9:02 pm, Stefan Ram wrote:
> Noel Duffy <uaigh@icloud.com> writes:
>> On 27/01/23 08:50, Stefan Ram wrote:
>>> By an incredible twist of fate, I came across a chapter of
>>> a book that explained dynamic programming and how to use it
>>> to reduce the complexity of global paragraph wrapping from
>>> exponential to quadratic!
>> Well don't keep us in suspense! What's the book?
>
> |The Computer Science of TeX and LaTeX;
> |based on CS 594, fall 2004, University of Tennessee
> |
> |Victor Eijkhout
> |Texas Advanced Computing Center
> |The University of Texas at Austin
> |
> |2012

Did you even notice my reply re the food dish question?

--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

Re: Paragraph Wrapping

<dish-20230202225910@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=4039&group=comp.programming#4039

  copy link   Newsgroups: comp.programming
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.programming
Subject: Re: Paragraph Wrapping
Date: 2 Feb 2023 22:03:06 GMT
Organization: Stefan Ram
Lines: 39
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <dish-20230202225910@ram.dialup.fu-berlin.de>
References: <wrap-20230126195034@ram.dialup.fu-berlin.de> <tqumg4$1aqqf$1@dont-email.me> <book-20230202220128@ram.dialup.fu-berlin.de> <trhas0$j6m3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de ZF4XIk9TMp4uPOYZMwJw7gi+JbW/2do4t1MUF1Qk2Mfzpf
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 2 Feb 2023 22:03 UTC

Richard Heathfield <rjh@cpax.org.uk> writes:
>Did you even notice my reply re the food dish question?

Yes. Sorry. I should have written a reply!

So, what that book by Eijkhout said is in my words:

The last dish could be anything, so that its expected value of
the rating function on the scale from 0 to 1 is equal to 0.5.

Therefore, one would choose the penultimate dish if its
rating is better than 0.5, because then it would be better
than the alternative.

If one assumes that the penultimate dish can be anything, it is
better than 0.5 in half of the cases, in such a case, one would
choose it, and since it then lies somewhere between 0.5 and 1, the
expected value is then 0.75. Otherwise, one takes the last dish with
an expected value of 0.5. Overall, with this strategy and two dishes,
the expected value is then the mean of 0.75 and 0.5, i.e., 0.625.

So, the second-to-last dish would have to be better than 0.625
in order to be chosen.
I wrote a small Python program to compare this with the strategy you
mentioned. The result is that the strategy given above fares better
by a factor of 1.2146 if every dish's quality is randomly between 0
and 1. But the traditional strategy you gave fares better by a factor
between 0.8 and 0.99 when the quality of all the dishes is a priori
restricted to some range [a,b], where a < b and 0 <= a <= 1, at least
for three such cases I looked at.

Which is "the best" solution, then, might depend on details of
the wording of the question, i.e., whether it states that every
dish can have an arbitrary quality between 0 and 1 or whether
a certain cook always produces dishes between a and b (but how
could he know or control the ratings the customer will give?).

Re: Paragraph Wrapping

<ab-20230202231001@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=4040&group=comp.programming#4040

  copy link   Newsgroups: comp.programming
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.programming
Subject: Re: Paragraph Wrapping
Date: 2 Feb 2023 22:10:13 GMT
Organization: Stefan Ram
Lines: 6
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <ab-20230202231001@ram.dialup.fu-berlin.de>
References: <wrap-20230126195034@ram.dialup.fu-berlin.de> <tqumg4$1aqqf$1@dont-email.me> <book-20230202220128@ram.dialup.fu-berlin.de> <trhas0$j6m3$1@dont-email.me> <dish-20230202225910@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 1mf8uI9cSR//c46pV/F8uQ1TSLQja4WymETYlwP9aHW+z3
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 2 Feb 2023 22:10 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>restricted to some range [a,b], where a < b and 0 <= a <= 1, at least

restricted to some range [a,b], where a < b and 0 <= a, b <= 1, at least

Re: Paragraph Wrapping

<strategies-20230202234935@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=4041&group=comp.programming#4041

  copy link   Newsgroups: comp.programming
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.programming
Subject: Re: Paragraph Wrapping
Date: 2 Feb 2023 22:56:09 GMT
Organization: Stefan Ram
Lines: 95
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <strategies-20230202234935@ram.dialup.fu-berlin.de>
References: <wrap-20230126195034@ram.dialup.fu-berlin.de> <tqumg4$1aqqf$1@dont-email.me> <book-20230202220128@ram.dialup.fu-berlin.de> <trhas0$j6m3$1@dont-email.me> <dish-20230202225910@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de NWLxCWsHcPsj5StPPvO0gwtlLP77BegAk4GnKjAs9T+OAx
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Thu, 2 Feb 2023 22:56 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>If one assumes that the penultimate dish can be anything, it is
>better than 0.5 in half of the cases, in such a case, one would

That was a comma splice; it should read: "... cases; in ...".

>I wrote a small Python program to compare this with the strategy you
>mentioned. The result is that the strategy given above fares better
>by a factor of 1.2146 if every dish's quality is randomly between 0

... or some value near 1.2146

>and 1. But the traditional strategy you gave fares better by a factor
>between 0.8 and 0.99 when the quality of all the dishes is a priori
>restricted to some range [a,b], where a < b and 0 <= a <= 1, at least
>for three such cases I looked at.

Here's that Python program:

# Python 3.8

import itertools
import random

last_dish = 4

def calculate_thresholds_for_the_dynamic_method():
global threshold
threshold =[ None ]*( last_dish + 1 )
for position in range( last_dish, -1, -1 ):
if position == last_dish:
expectation_value = 0.5
else:
expectation_value_if_chosen =( 1 + expectation_value )/ 2
probability_of_choice =( 1 - expectation_value )
expectation_value = \
expectation_value_if_chosen * probability_of_choice + \
expectation_value *( 1 - probability_of_choice )
threshold[ position ]= expectation_value

def generation_of_five_random_numbers():
global numbers
numbers = []
for _ in range( last_dish + 1 ):
numbers.append( random.random() )

def traditional_strategy():
seen = []
for dish in range( last_dish + 1 ):
number = numbers[ dish ]
if dish in[ 0, 1 ]:
seen.append( number )
elif dish in[ 2, 3 ]:
if number > max( seen ):
return dish
seen.append( number )
else: return dish

def dynamic_strategy():
for dish in range( last_dish + 1 ):
number = numbers[ dish ]
if number > threshold[ dish ]: return dish
if dish == last_dish: return dish

def compare_both_strategies_using_the_expectation_value():
calculate_thresholds_for_the_dynamic_method()
traditional_total = 0
dynamic_total = 0
for i in itertools.count():
generation_of_five_random_numbers()
traditional_result = numbers[ traditional_strategy() ]
dynamic_result = numbers[ dynamic_strategy() ]
traditional_total += traditional_result
dynamic_total += dynamic_result
if not( i % 100000 ):
print( f'{dynamic_total/traditional_total=:.5}' )

def compare_both_strategies_using_finding_the_best():
calculate_thresholds_for_the_dynamic_method()
traditional_count = 0
dynamic_total = 0
for i in itertools.count():
generation_of_five_random_numbers()
traditional_result = numbers[ traditional_strategy() ]
dynamic_result = numbers[ dynamic_strategy() ]
if traditional_result == max( numbers ): traditional_total += 1
if dynamic_result == max( numbers ): dynamic_total += 1
if not( i % 100000 ):
print( f'{dynamic_total/traditional_total=:.5}' )

compare_both_strategies_using_the_expectation_value()

.

Re: Paragraph Wrapping

<c91ed50f-3b38-4677-9701-892d8b57e918n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=4042&group=comp.programming#4042

  copy link   Newsgroups: comp.programming
X-Received: by 2002:a37:e20d:0:b0:72f:7b06:601b with SMTP id g13-20020a37e20d000000b0072f7b06601bmr99314qki.96.1675434246267;
Fri, 03 Feb 2023 06:24:06 -0800 (PST)
X-Received: by 2002:a05:6871:552:b0:163:ac2d:c4d with SMTP id
t18-20020a056871055200b00163ac2d0c4dmr523173oal.192.1675434245995; Fri, 03
Feb 2023 06:24:05 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.programming
Date: Fri, 3 Feb 2023 06:24:05 -0800 (PST)
In-Reply-To: <tqumg4$1aqqf$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=82.131.36.154; posting-account=ogslnwoAAACd9vU9PADzlWBA81fSuNpL
NNTP-Posting-Host: 82.131.36.154
References: <wrap-20230126195034@ram.dialup.fu-berlin.de> <tqumg4$1aqqf$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c91ed50f-3b38-4677-9701-892d8b57e918n@googlegroups.com>
Subject: Re: Paragraph Wrapping
From: air000000000000@ya.ee (Y A)
Injection-Date: Fri, 03 Feb 2023 14:24:06 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1624
 by: Y A - Fri, 3 Feb 2023 14:24 UTC

div {
word-wrap: break-word;
}

On Thursday, January 26, 2023 at 10:06:33 PM UTC+2, Noel Duffy wrote:
> On 27/01/23 08:50, Stefan Ram wrote:
> > By an incredible twist of fate, I came across a chapter of
> > a book that explained dynamic programming and how to use it
> > to reduce the complexity of global paragraph wrapping from
> > exponential to quadratic!
>
> Well don't keep us in suspense! What's the book?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor