Governance by those who do the work.
Sunday, December 25, 2011
"Mathematical Marbling" to appear in IEEE Computer Graphics and Applications
A paper on marbling, which I wrote with Shufang Lu, Xiaogang Jin, Hanli Zhao, and Xiaoyang Mao has been accepted for publication:
Lu, S.; Jaffer, A.; Jin, X.; Zhao, H.; Mao, X.; ,
"Mathematical Marbling,"
Computer Graphics and Applications, IEEE , vol.PP, no.99, pp.1, 0
doi: 10.1109/MCG.2011.51
http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=5887299&isnumber=5185484
Wednesday, November 30, 2011
The Colors of Heat
At a given temperature, a blackbody will emit more light than any other surface. The table below shows the colors of a blackbody at exponentially decreasing absolute temperate. The left column of colors is how they would naturally appear. The top color is a sky blue, which has a color temperature of approximately 10000 K.
In the right column, each temperature's chromaticity is scaled proportionally to its Celsius temperature.
Read more at http://people.csail.mit.edu/jaffer/Color/Heat.
Saturday, August 20, 2011
Script to Monitor Websites
What is needed is an automated method to periodically check websites and notify me when their status changes (up or down). This method must involve a computer other than the one hosting the website, because a stopped computer can't notify me of anything.
I have created a Unix script "wstatus" to be run periodically by crontab. Its first argument is a URL to retrieve from the website; the second is the email address to send notifications to. The wstatus script puts small files in a $(HOME)/.status/ directory (.status in your home directory).
The crontab entry:
*/10 * * * * $HOME/bin/wstatus http://voluntocracy.org/server-status.txt jaffer@localhostreads "server-status.txt" from "http://voluntocracy.org" every 10 minutes. If the content or error retrieved differs from the last, then the first line of that content or error is emailed to me (locally). "server-status.txt" contains just the line "voluntocracy.org is up!".
I wonder how often my ISP changes my IP-address:
25 * * * * $HOME/bin/wstatus http://automation.whatismyip.com/n09230945.asp jaffer@localhostcheckes once an hour (at 25 minutes past). Of course, if I move my computer to another network, I get an email notifying me of the change. If you use automation.whatismyip.com, be sure to observe their rule: We ask that automated files hit our site no more then once every five minutes or once every 300 seconds.
The early version of wstatus consisted of just the black code below. But it occasionally sent two email notices for a single change of status when the cron period was small. I believe this happens because cron starts its child processes with less (numerically higher) priority than users have; and these processes queue up while higher priority jobs are running.
The code in red was added to dismiss a wstatus process if another is already running. Among the basic Unix file commands, only rm (ReMove file) returns a status allowing it to be used as a mutex. Thus, to grab the mutex the script tries to remove a file with the extension ".idl". If it succeeded, the script continues to run; otherwise it exits immediately.
This will work except if the script is interrupted and does not restore the ".idl" file. To handle this case, the line in green was added to restore the ".idl" file when the script exits because it doesn't grab the mutex. Whereas the code without the green line will generate only one email per change no matter how many wstatus processes are running simultaneously, with the green line, only suppression of the second wstatus process is guaranteed. If it is the case that double processes occur more frequently than higher multiples, then this approach is reasonable.
The use of rm as a mutex is rare, perhaps novel. I have not tested whether rm is actually atomic; but even if it isn't, it reduces by an order of magnitude the window of opportunity for repeated messages from wstatus.
Wednesday, July 6, 2011
Recurrence for Multidimensional Self-Similar Functions
Staring at this diagram of the Peano space-filling curve inspired the recurrence formula, something I have been seeking for a couple of years. It remains to derive the inverse function and generalize the recurrence to produce Hilbert space-filling functions as well.
If the unit cell is a Hamiltonian Path, the resulting function is a space-filling curve. Functions resulting from unit cells which don't connect all their nodes are still self-similar (fractal).
Once the formula was discovered, creating a better space-filling curve, one which is nearly isotropic, is not difficult. This may not be novel in 2 dimensions, but the higher dimensional varieties are.
Sunday, June 12, 2011
Free Convection from Rectangular Plate
Free convection correlations for inclined rectangular plates involve characteristic-lengths LH, LW, and L* (area divided by perimeter). Each correlation is computed using its own characteristic-length. Flows are then compared and selected as convective surface-conductances (h).
Proposed is the complete free convective surface conductance for one side of a flat LH by LW rectangular isothermal plate inclined θ around the level edge which is LW long.
L* = | LH⋅LW / (2 (LH+LW)) | |||||
R = | min(LH, LW)/2 | |||||
Pr = | cp⋅μ/k | |||||
Ra(L) = | |ΔT|⋅g⋅ρ2⋅cp⋅L3 / (T⋅μ⋅k) | |||||
HHT*(Ra*) = | {0.65 + 0.36 Ra*1/6}2 | 1≤Ra*≤1.5×109 | θ=−90° | |||
T9.3(Ra) = | {.825 + | .387 Ra1/6 [1+(.492/Pr)9/16]8/27 | }2 | 1≤Ra≤1012 | θ=0° | |
Nu45(Ra) = | 0.544 Ra1/5 [1+(0.785/Pr)3/5]1/3 | θ=+90° |
h = k⋅max( | Nu45(Ra(R)) R | , | T9.3(Ra(LH) cos θ) LH | ) | 0°≤θ≤90° | UCT3 | ||
h = k⋅max( | HHT*(Ra(L*) sin(−θ)) L* | , | T9.3(Ra(LH) cos θ) LH | ) | −90°≤θ≤0° | UHT3 |
Sunday, May 8, 2011
Excess Fructose Content of Foods
Fructose and glucose are simultaneously absorbed in equal amounts by the intestines. Excess fructose is absorbed by a different mechanism. In individuals with fructose malabsorption, excess fructose remains in the intestines where fermentation causes gastric distress.
Glucose requires insulin to be absorbed from the bloodstream, while fructose does not. There has been vigorous debate as to whether individuals with Diabetes mellitus (a metabolic disease characterized by high blood sugar) should consume or avoid fructose.
In any case, it would be interesting to have a chart showing the spectrum of fructose-heavy to glucose-heavy foods.
The USDA National Nutrient Database gives nutrient values for 7636 foods; but only 1134 of them have fructose and glucose values.
This database was used to create a table of the 1134 foods having fructose and glucose values. The foods are listed in order of decreasing amount of excess fructose.
The database doesn't give data for High Fructose Corn Syrup. Used mostly in soft drinks, HFCS 55 is composed of approximately 55% fructose and 42% glucose. This would give it a 13% excess of fructose, comparable to the 15% and 20% fructose excesses of lemonade powders near the top of the chart.
When dried, the Agave americana plant pictured above has the most excess fructose (39%) of the foods in the database.
Wednesday, March 23, 2011
Design Pattern for Multi-Format Extract-Transform-Load
Presented is a design-pattern for single-pass extract-transform-load (ETL) processing of line-oriented files which automatically detects the line format, but which does not require any domain-specific code devoted to deciding the format of the input file.
The Color-Name Dictionaries web-page analyzes and compares more than 3 dozen color dictionaries from book and online sources. The dictionary sources are in 19 (plain-text and HTML) formats. The largest is the "NBS/ISCC Dictionary of Color Names" with 5411 color names; and there are several with over 1300 names. Some color dictionaries are updated or added every year.
The dictionary files share these characteristics:
- Each color-name entry appears on a single line.
- All the intended color-name entries in a file have the same
format. - A Preamble and comments may be mixed with the color-name
entries.
There are format errors, inconsistencies, duplicates, and collisions (where a color name is repeated with different color coordinates) in some of the files. In spite of this, file->color-dictionary and url->color-dictionary in the SLIB color-database module are able to automatically detect the format and extract and clean the data and insert it into relational tables. This is accomplished in an easy-to-extend fashion using closures. This code is written in Scheme, but the same idea should work in any language with closures.
The main ETL loop has port bound to an input-stream reading from the dictionary source file:
(do ((line (read-line port) (read-line port))) ((eof-object? line) (display "Inserted ") (display *idx*) (display " colors") (newline) *rcs-header*) (let ((colin (parse-rgb-line line))) (cond ((equal? "" line)) ((not colin) (write-line line)) ((numbered-gray? (cadr colin))) (else (for-each (lambda (name) (let ((oclin (color-table:row-retrieve name))) (cond ((and oclin (equal? (car colin) (cadr oclin)))) ((not oclin) (set! *idx* (+ 1 *idx*)) (color-table:row-insert (list name (car colin) *idx*))) (else (slib:warn 'collision colin oclin))))) (cdr colin))))))
The do loop iterates over the lines read from port, calling parse-rgb-line on each. The call to parse-rgb-line returns false unless the line was parsed as a valid color-dictionary line. If it returns false, line is printed to the log. If it returns a data row, each name in the row is checked for an existing table entry; if it matches, nothing is done; if it doesn't match, a warning is generated; if there is no entry, then it is created.
(define (parse-rgb-line line) ... (for-each (lambda (method) (or ans (let ((try (method line))) (cond (try (set! ans try) (display "**** Using method ") (display method-id) (newline) (set! parse-rgb-line method)))))) (list (lambda (line) ...) (lambda (line) ...) ... )))
The construction of parse-rgb-line is a bit unusual. The for-each procedure calls its first argument (lambda (method) ...)
with each function (lambda (line) ...)
in the list which is its second argument. The first-argument procedure returns immediately if ans is not false. Otherwise, it calls method with the input line. If method returns a data row, then ans is set to it, and no other methods will be called. The test of ans can be eliminated through the use of an escape continuation.
Most importantly, when method returns a data row, it sets parse-rgb-line to method, so that after the current invocation of parse-rgb-line returns (or escapes), the method which worked will be called directly. Thus parse-rgb-line is a self-replacing function!
If parse-rgb-line is defined internally to another procedure, the containing procedure can be reentrant (as SLIB is).
Here is a typical (lambda (line) ...)
function:
(lambda (line) (case (sscanf line " %24[a-zA-Z0-9_ ] %d %d %d %e %e %e %s" name r g b ri gi bi junk) ((7) (set! method-id 'm7) (list (check-match line (color:sRGB r g b) (floats->rgb ri gi bi)) (color-name:canonicalize name))) (else #f)))
sscanf is called with 8 variables, but this function will succeed only if exactly 7 are scanned; this is to detect extra stuff on the line. method-id is for reporting which method succeeded. check-match is called to warn if the RGB integer coordinates don't match the floating-point color coordinates.
If a format needs to ignore junk at the end of lines, then it should come after any functions (in the list) whose formats it might spoof. This way, the more specific format takes precedence.
Conclusion
A design-pattern employing a self-replacing function provides single-pass ETL processing of line-oriented files which automatically detects the line format.