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!
On 27/01/23 08:50, Stefan Ram wrote:
By an incredible twist of fate, I came across a chapter ofWell don't keep us in suspense! What's the book?
a book that explained dynamic programming and how to use it
to reduce the complexity of global paragraph wrapping from
exponential to quadratic!
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 . . .
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!
On 27/01/23 08:50, Stefan Ram wrote:
By an incredible twist of fate, I came across a chapter ofWell don't keep us in suspense! What's the book?
a book that explained dynamic programming and how to use it
to reduce the complexity of global paragraph wrapping from
exponential to quadratic!
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 ofWell don't keep us in suspense! What's the book?
a book that explained dynamic programming and how to use it
to reduce the complexity of global paragraph wrapping from
exponential to quadratic!
|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?
restricted to some range [a,b], where a < b and 0 <= a <= 1, at least
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
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.
On 27/01/23 08:50, Stefan Ram wrote:--- Synchronet 3.20a-Linux NewsLink 1.113
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?
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--- Synchronet 3.20a-Linux NewsLink 1.114
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
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 910 |
Nodes: | 10 (1 / 9) |
Uptime: | 116:14:18 |
Calls: | 12,128 |
Calls today: | 2 |
Files: | 186,512 |
Messages: | 2,230,106 |