calculate merge ratio by dot products; use instanceof when checking object types