function [thermometer,mercuryColumn,temperatureLabel,mThermTick, sigmoidAxes] ...
	= hopThermometer( Tmax );

% hopThermometer.m
%
%  Construct a thermometer and coordinates for mercury column
%  and temperature label for a Boltzmann machine.
%  kornel laskowski & dave touretzky (c) 2004
%  cmu 15-782 artificial neural networks

xLim = get(gca,'XLim');
yLim = get(gca,'YLim');

bThermTick = yLim(1) + 0.30 * yLim(2);
mThermTick = (yLim(2) - yLim(1))/20;

xLeftThermTick = xLim(2) - (xLim(2) - xLim(1))/15;
xRightThermTick = xLim(2);

thermometer(1) = line( [ xLeftThermTick xRightThermTick ], ...
	[ bThermTick               bThermTick       ], ...
	[ -1 -1 ], 'Color', [1 1 1] );
thermometer(2) = line( [ xLeftThermTick xRightThermTick ], ...
	[ bThermTick+   mThermTick bThermTick+   mThermTick ], ...
	[ -1 -1 ], 'Color', [1 1 1] );
thermometer(3) = line( [ xLeftThermTick xRightThermTick ], ...
	[ bThermTick+ 2*mThermTick bThermTick+ 2*mThermTick ], ...
	[ -1 -1 ], 'Color', [1 1 1] );
thermometer(4) = line( [ xLeftThermTick xRightThermTick ], ...
	[ bThermTick+ 3*mThermTick bThermTick+ 3*mThermTick ], ...
	[ -1 -1 ], 'Color', [1 1 1] );
thermometer(5) = line( [ xLeftThermTick xRightThermTick ], ...
	[ bThermTick+ 4*mThermTick bThermTick+ 4*mThermTick ], ...
	[ -1 -1 ], 'Color', [1 1 1] );
thermometer(6) = line( [ xLeftThermTick xRightThermTick ], ...
	[ bThermTick+ 5*mThermTick bThermTick+ 5*mThermTick ], ...
	[ -1 -1 ], 'Color', [1 1 1] );
thermometer(7) = line( [ xLeftThermTick xRightThermTick ], ...
	[ bThermTick+ 6*mThermTick bThermTick+ 6*mThermTick ], ...
	[ -1 -1 ], 'Color', [1 1 1] );
thermometer(8) = line( [ xLeftThermTick xRightThermTick ], ...
	[ bThermTick+ 7*mThermTick bThermTick+ 7*mThermTick ], ...
	[ -1 -1 ], 'Color', [1 1 1] );
thermometer(9) = line( [ xLeftThermTick xRightThermTick ], ...
	[ bThermTick+ 8*mThermTick bThermTick+ 8*mThermTick ], ...
	[ -1 -1 ], 'Color', [1 1 1] );
thermometer(10) = line( [ xLeftThermTick xRightThermTick ], ...
	[ bThermTick+ 9*mThermTick bThermTick+ 9*mThermTick ], ...
	[ -1 -1 ], 'Color', [1 1 1] );
thermometer(11) = line( [ xLeftThermTick xRightThermTick ], ...
	[ bThermTick+10*mThermTick bThermTick+10*mThermTick ], ...
	[ -1 -1 ], 'Color', [1 1 1] );

capillaryRadius = (xRightThermTick - xLeftThermTick) / 4;
capillaryCenter = xLeftThermTick + (xRightThermTick - xLeftThermTick)/2;
yBulbHeight = bThermTick - mThermTick;

angle = 0 : pi/20 : pi;
xVessel = capillaryRadius * cos(angle);
yVessel = 11 * mThermTick + capillaryRadius * sin(angle);
xVessel = [ capillaryRadius xVessel -capillaryRadius ];
yVessel = [ 0 yVessel 0 ];

thermometer(12) = line( capillaryCenter + xVessel, yBulbHeight + yVessel, ...
	-1 * ones(1,length(angle)+2), 'Color', [1 1 1] );

angle = 0 : pi/20 : 2*pi;
xBulb = 2 * capillaryRadius * cos(angle);
yBulb = 2 * capillaryRadius * sin(angle);

thermometer(13) = line( capillaryCenter + xBulb, yBulbHeight + yBulb, ...
	-1 * ones(1,length(angle)), 'Color', [1 1 1] );

thermometer(14) = patch( capillaryCenter + 0.9 * xBulb, ...
	yBulbHeight + 0.9 * yBulb, [1 0 0] );
thermometer(15) = rectangle( 'Position', [ ...
		capillaryCenter - 0.8 * capillaryRadius, ...
		yBulbHeight, ...
		0.8 * 2 * capillaryRadius, ...
		bThermTick - yBulbHeight ...
	], 'FaceColor', [1 0 0], 'LineStyle', 'none' );

mercuryColumn = rectangle( 'Position', [ ...
		capillaryCenter - 0.8 * capillaryRadius, ...
		bThermTick, ...
		0.8 * 2 * capillaryRadius, ...
		10 * mThermTick ...
	], 'FaceColor', [1 0 0], 'LineStyle', 'none' );

temperatureLabel = text( ...
		'Position', [capillaryCenter yBulbHeight - mThermTick], ...
		'HorizontalAlignment','center', ...
		'VerticalAlignment','top', ...
		'String', sprintf('%.3f',Tmax), ...
		'FontSize',12,'FontWeight','bold', ...
		'Color', [1 0 0] );

axis([xLim(1) xLim(2) yLim(1) yLim(2)]);

sigmoidAxes = axes( 'Position', [0.87 0.1 0.1 0.1] );
axis([-10 10 -0.3 1.3])
cla
 
set(thermometer,'Visible','off');
set(mercuryColumn,'Visible','off');
set(temperatureLabel,'Visible','off');
axes(sigmoidAxes);
cla;
set(sigmoidAxes,'Visible','off');

mThermTick = mThermTick * (10 / Tmax);

