Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6655197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:29:15+00:00 2026-05-26T01:29:15+00:00

I am building a system in Clojure that consumes events in real time and

  • 0

I am building a system in Clojure that consumes events in real time and acts on them according to how many similar messages were received recently. I would like to implement this using a recency score based on Newtonian cooling.

In other words, when an event arrives, I want to be able to assign it a score between 1.0 (never happened before, or “ambient temperature” in Newton’s equation) and 10.0 (hot hot hot, has occurred several times in the past minute).

I have a vague idea of what this data structure looks like – every “event type” is a map key, and every map value should contain some set of timestamps for previous events, and perhaps a running average of the current “heat” for that event type, but I can’t quite figure out how to start implementing beyond that. Specifically I’m having trouble figuring out how to go from Newton’s actual equation, which is very generic, and apply it to this specific scenario.

Does anyone have any pointers? Could someone suggest a simpler “recency score algorithm” to get me started, that could be replaced by Newtonian cooling down the road?

EDIT: Here is some clojure code! It refers to the events as letters but could obviously be repurposed to take any other sort of object.

(ns heater.core
    (:require [clojure.contrib.generic.math-functions :as math]))

(def letter-recency-map (ref {}))

(def MIN-TEMP 1.0)
(def MAX-TEMP 10.0)
;; Cooling time is 15 seconds
(def COOLING-TIME 15000)
;; Events required to reach max heat
(def EVENTS-TO-HEAT 5.0)

(defn temp-since [t since now]
    (+
        MIN-TEMP
        (*
            (math/exp (/
                (- (- now since))
                COOLING-TIME))
            (- t MIN-TEMP))))

(defn temp-post-event [temp-pre-event]
    (+ temp-pre-event
        (/
            (- MAX-TEMP temp-pre-event)
            EVENTS-TO-HEAT)))

(defn get-letter-heat [letter]
        (dosync
            (let [heat-record (get (ensure letter-recency-map) letter)]
            (if (= heat-record nil)
                (do
                (alter letter-recency-map conj {letter {:time (System/currentTimeMillis) :heat 1.0}})
                MIN-TEMP)
                (let [now (System/currentTimeMillis)
                     new-temp-cooled (temp-since (:heat heat-record) (:time heat-record) now)
                     new-temp-event (temp-post-event new-temp-cooled)]
                     (alter letter-recency-map conj {letter {:time now :heat new-temp-event}})
                    new-temp-event)))))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:29:16+00:00Added an answer on May 26, 2026 at 1:29 am

    In absence of any events, the solution to the cooling equation is exponential decay. Say T_0 is the temperature at the beginning of a cooling period, and dt is the timestep (computed from system time or whatever) since you evaluated the temperature to be T_0:

    T_no_events(dt) = T_min + (T_0 - T_min)*exp(- dt / t_cooling)
    

    Since your events are discrete impulses, and you have a maximum temperature, you want a given ratio per event:

    T_post_event = T_pre_event + (T_max - T_pre_event) / num_events_to_heat
    

    Some notes:

    • t_cooling is the time for things to cool off by a factor of 1/e = 1/(2.718...).

    • num_events_to_heat is the number of events required to have an effect comparable to T_max. It should probably be a moderately large positive value (say 5.0 or more?). Note that if num_events_to_heat==1.0, every event will reset the temperature to T_max, which isn’t very interesting, so the value should at the very least be greater than one.

    • Theoretically, both heating and cooling should never quite reach the maximum and minimum temperatures, respectively (assuming parameters are set as above, and that you’re starting somewhere in between). In practice, though, the exponential nature of the process should get close enough as makes no difference…

    • To implement this, you only need to store the timestamp and temperature of the last update. When you receive an event, do a cooling step, then a heating event, and update with the new temperature and timestamp.

    • Note that read-only queries don’t require an update: you can just compute the cooling since the last update.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a system that consists of many clients connecting to a server. The
I'm building a system to show a bit of real time activity on a
I'm building a system that shows events for this month, listed by day and
We're currently building a system that abstracts all kinds of technical details about web
I am building a multithreaded system that works like this: While there are entities:
I'm building a plugin system for my application. I've read that anyone can decomple
I'm designing/building a system of classes that all derive from a single base class.
I'm building a system using django, Sphinx and MySQL that's very quickly becoming quite
I am building a system that stores articles and tags that categorize the article.
I'm building a system of apps that listen for files dumped into a folder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.